Sunday 10 August 2014

Write an awk script that accepts date argument in the form of mm-dd-yy and displays it in the form if day, month, and year. The script should check the validity of the argument and in the case of error, display a suitable message.


BEGIN {
FS="-"
f=1;
printf("enter date with (mm-dd-yy) format:");
getline < "/dev/tty"
if(((($3%4!=0) && ($1==2) && ($2>28)) || (($3%4==0) && ($1==2) && ($2>29))) ||
((($1==1) || ($1==3) || ($1==5) || ($1==7) || ($1==8) || ($1==10) || ($1==12)) && ($2>31)) ||
((($1==4) || ($1==6) || ($1==9) || ($1==11)) && ($2>30)) || ($1<1) || ($2<1) || ($3<1) || ($1>12))
f=0;
if(f==0)
printf("you have entered an invalid date\n");
else
printf("\n \tThe date= %d\nThe month=%d\nThe year is=%d\n is valid date\n",$2,$1,$3);
}

1 comments:

Unknown said...

not working. useless code

Post a Comment

 
- |