I have the following shell script to append a header line to a batch of .csv files. I need to apply a different header txt file to each .csv based on the number of columns in the input csv. The script is working in that it is applying the header files and outputting the new csv, but every file is getting the 'else' header--including the csv's that evaluate to '91' with the csvgrep -n $f | wc -l
command.
#!/bin/sh
dir="/Users/XXX/xlsxtocsv"
#move to the csvraw output directory
cd csvraw/
#append the header row needed for DB import
for f in *.csv; do
if [[ "csvgrep -n $f | wc -l" == 91 ]]; then
cat $dir/svcheader3col.txt $f >> "$dir/csvhead/${f%}header.csv"
else
cat $dir/svcheader.txt $f >> "$dir/csvhead/${f%}header.csv"
fi
done
And when I run the csvgrep command manually on the csv files I get:
username:csvraw username$ csvgrep -n file4col.csv | wc -l
92
username:csvraw username$ csvgrep -n file3col.csv | wc -l
91
Why is the "file3col.csv" file not evaluating to 91 in the if statement, but is when I run it manually?
Aucun commentaire:
Enregistrer un commentaire