Hi,
In my previous post I looked for timestamp to be added to the filename
http://www.unix.com/shell-programming-scripting/230603-how-append-timestamp-filenames-using-find.html
Now how do I select those files that do not have timestamp in the filenames.
I tried the following. My file has extension either *.out or *.bad.
echo "abcdef.test.1234.20130722133919.out" | grep -v '[0-9]\{14\}\.[out|bad]'
Though it did give good results, the above code can be any 14 consecutive numbers. How does the grep/sed/awk knows the pattern as YYYYDDMMHHMISS.out or YYYYDDMMHHMISS.bad
The script should not pick the files that has timestamp in the filename.
Thanks for your help
With GNU/Linux utilities:
x='abcdef.test.1234.20130722133919.out'
echo $x | cut -d. -f4 | sed 's/\(.\{8\}\)\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1 \2:\3:\4/' | xargs -I{} date -d {} 1&>/dev/null
if [ $? -ne 0 ]
then
echo "Bad date in file"
exit 1
fi
I encountered the following error
date: illegal option -- d
Usage: date [-u] [+Field Descriptors]
I have the following version of unix (ksh)
AIX <hostname> 1 6 00F736154C00
Try this regular expression in grep. Be warned that this regex is better than the one in post #1, but not completely fool-proof. For e.g., it could still give a GO for 20130631 or 20130230 which are invalid dates.
201[0-9]\(0[1-9]\|1[0-2]\)\([0-2][1-9]\|3[01]\)\([01][0-9]\|2[0-3]\)[0-5][0-9][0-5][0-9]\.\(out\|bad\)