I have a directory full of files with the date they were created in the filename (ie "mvr-20160420.csv"). The files contain comma delimited data that I'm combining into a single text file. I'm trying to figure out how to add the date portion of each file to the data. I'm able to read the files, but not the filenames.
Sample file for mvr-20160420.csv:
client employee id,first name,last name,points
14204,Bob,Smith,5
I have a Korn script and just trying to add the filename to the data:
for file in $Folder/path/burnsmcd-mvr*.csv
do
FN=file
if [ $FIRSTTIME = $STATUS_OK ]
then
FIRSTTIME=$STATUS_NOT_OK
cat $file | strings | sort -n | awk 'BEGIN{FS=","}{OFS="|"}{if ( $1 ~ /^[0-9]+$/) print "ADMVR", $1, $2, $3, $4, $FN}' > $Folder/path/ext_test.txt
else
cat $file | strings | sort -n | awk 'BEGIN{FS=","}{OFS="|"}{if ( $1 ~ /^[0-9]+$/) print "ADMVR", $1, $2, $3, $4, $FN}' >> $Folder/path/ext_test.txt
fi
done
So my output ext_test.txt looks like this:
14204|Bob|Smith|5|14204,Bob,Smith,5
I can't seem to add the filename. I also need to extract the date portion.
$FNis wrong there, try$file. And don't usecat, just dostrings $file | sort ....