Hi, I am new to unix shell script and I have some trouble on the awk sub
I would like to pick the Date "July 10 2012" into $corr_date by using sub() function, but it is not successful.
The inputted text file:
pic.*.txt
July 10 2012 20:30:50 , 1234567.jpg
July 10 2012 20:30:52 , 5648978.jpg
July 10 2012 20:30:53 , 6405789.jpg
#!/bin/ksh
curr_date=`date +"%B %d %Y"`
for i in `ls -1 pic.*.txt`
do
Date=`tail -1 $i |awk 'BEGIN {FS=","} {print $1}'`
corr_date=`awk '{sub(/[0-9]+:[0-9]+:[0-9]+/,"") ; print;}' Date`
if [ "$corr_date" = "$curr_date"]; then
echo "$corr_date is valid."
else
echo "$corr_date is invalid"
fi
done
exit
This is the error msg:
awk: syntax error near line 1
awk: illegal statement near line 1
Thanks