With GNU utils everything is simpler but well... AIX 6
echo '20170001
20319900
20110232
20000001
20160230
20160229' | while read d; do
date -d$d '+%Y%m%d'; done
date: invalid date �20170001�
date: invalid date �20319900�
date: invalid date �20110232�
date: invalid date �20000001�
date: invalid date �20160230�
20160229
But I think this egrep expression is enough for practical needs (only for 2000-2016 years)
awk -F '.' '{
IF($1== mohan_moh)
then print ok
elif ($2= --some regular expression to validate date) here $2 is 20151222
then print ok
elif ($3= --some regular expression to validate date) here $3 is 20151222
then print ok
elif ($4= --some regular expression to validate time) here $4 is 122442
then print ok
else
print nok
fi}
please suggest me something like so validate name string date and time in single awk command in AIX 6
---------- Post updated at 11:52 AM ---------- Previous update was at 11:50 AM ----------
please suggest me something like so validate name string date and time in single awk command in AIX 6
my sample code
awk -F '.' '{
IF($1== mohan_moh)
then print ok
elif ($2= --some regular expression to validate date) here $2 is 20151222
then print ok
elif ($3= --some regular expression to validate date) here $3 is 20151222
then print ok
elif ($4= --some regular expression to validate time) here $4 is 122442
then print ok
else
print nok
fi}
use strict;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $yyyymmdd = sprintf "%.4d%.2d%.2d", $year+1900, $mon+1, $mday;
### CHECK THIS LINE
my $last="122442"; # Just make this to whatever required like Date time etc etc
# TEST with below file name to match my system date
#mohan_moh.20160115.20160115.122442.txt"
while (<STDIN>) {
chomp;
if ( $_ =~ m/mohan_moh\.\Q$yyyymmdd\E\.\Q$yyyymmdd\E\.\Q$last\E\.txt/ )
{ print "\n$_ FILEName is [ OK ]\n"; }
else
{ print "\n $_ FILEName is [ BAD ]\n"; }
}