3 deleted 14 characters in body; edited title
source | link

Need help parsing Parsing a filename and adding it to a text file

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 could also use some help extracting also need to extract the date portion.

Need help parsing a filename and adding it to a text file

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 could also use some help extracting the date portion.

Parsing a filename and adding it to a text file

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.

2 deleted 18 characters in body
source | link

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

client employee id,first name,last name,points
14204,Bob,Smith,5

I have a Kron ScriptKorn script and just trying to add the filename to the data: for file in $Folder/path/burnsmcd-mvr*.csv do FN=file

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

done

So my output ext_test.txt looks like this: 14204|Bob|Smith|5|14204,Bob,Smith,5

14204|Bob|Smith|5|14204,Bob,Smith,5

I can't seem to add the filename. I could also use some help extracting the date portion.

Thanks for any help you can provide.

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 Kron 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 could also use some help extracting the date portion.

Thanks for any help you can provide.

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 could also use some help extracting the date portion.

1
source | link

Need help parsing a filename and adding it to a text file

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 Kron 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 could also use some help extracting the date portion.

Thanks for any help you can provide.