Normally I would think this to be an easy task but I guess I am having a bad week... I have searched but did not find a solution, hence the post.
Ok, so I have 40 or so files with data I need to clean up and build a report from. I am thinking of pulling the data I need from the files via awk. I will need to sequence thru the files in the directory one at a time, I am thinking ”ls” into an array and then a for loop. In the loop I need to read each line via sed or awk to find “Adding” at the beginning of the line. On the returned lines I need to print the file name contained in the string and add on the date which is a variable pulled from the source file name.
Files:
09-13-11-05-49-35-PM.txt
09-14-11-04-43-45-PM.txt
09-16-11-03-22-14-PM.txt
Sample lines:
(09-13-11-05-49-35-PM.txt)
Adding y:\path\path1\path2\path3\file name 1.docm 0% 1% OK
Adding y:\path\path1\path2\path3\file number 2.docm 1% 2% 3% OK
(09-14-11-04-43-45-PM.txt)
Adding y:\path\path1\path2\path3\word doc 1.doc 3% OK
(09-16-11-03-22-14-PM.txt)
Adding y:\path\path1\path2\path3\path 4\path 5\long filename used here.doc 3% OK
Desired output:
report.rpt
file name 1.docm 09/13/11
file number 2.docm 09/13/11
word doc 1.doc 09/14/11
long filename used here.doc 09/16/11
Code so far…
I can’t seem to get the date variable to append to each line of files from that file. I only get it at the end of the list.
Any help and/or tweaks are greatly appreciated. Please feel free to suggest better ways to do things as I enjoy learning and I know my methods are barbaric at best...
Thanks,
Cybex
Ok, so I have 40 or so files with data I need to clean up and build a report from. I am thinking of pulling the data I need from the files via awk. I will need to sequence thru the files in the directory one at a time, I am thinking ”ls” into an array and then a for loop. In the loop I need to read each line via sed or awk to find “Adding” at the beginning of the line. On the returned lines I need to print the file name contained in the string and add on the date which is a variable pulled from the source file name.
Files:
09-13-11-05-49-35-PM.txt
09-14-11-04-43-45-PM.txt
09-16-11-03-22-14-PM.txt
Sample lines:
(09-13-11-05-49-35-PM.txt)
Adding y:\path\path1\path2\path3\file name 1.docm 0% 1% OK
Adding y:\path\path1\path2\path3\file number 2.docm 1% 2% 3% OK
(09-14-11-04-43-45-PM.txt)
Adding y:\path\path1\path2\path3\word doc 1.doc 3% OK
(09-16-11-03-22-14-PM.txt)
Adding y:\path\path1\path2\path3\path 4\path 5\long filename used here.doc 3% OK
Desired output:
report.rpt
file name 1.docm 09/13/11
file number 2.docm 09/13/11
word doc 1.doc 09/14/11
long filename used here.doc 09/16/11
Code so far…
Code:
#!/bin/bash
TFILES=( $(ls *-PM.txt) )
for (( i=0; i<${#TFILES[@]}; i++ ));
do
FDATE=`basename "${TFILES[$i]}" .txt | awk -F"-" '{print $1"/"$2"/"$3;}'`
FNAME= awk -F" " '/Adding/ {print $2;}' "${TFILES[$i]}" | awk -F"\\" '{print $NF}'
#FNAME= awk -F" " '/Adding/ {print $2;}' "${TFILES[$i]}" | awk -F"\\" '{print $NF}' | sed 's/$/$FDATE/'
FDATA=$FNAME" "$FDATE
#printf $FNAME \t $FDATE # >> report.rpt
#echo $FDATA
#echo $FNAME | awk '{print $0 " " $DATE}'
done
#echo $FDATA
#echo $FNAME # >> report.rpt
echo $FNAME
I can’t seem to get the date variable to append to each line of files from that file. I only get it at the end of the list.
Any help and/or tweaks are greatly appreciated. Please feel free to suggest better ways to do things as I enjoy learning and I know my methods are barbaric at best...
Thanks,
Cybex