Linux shell programing validating date

24-May-2015 13:34

if any invalid date is there i have to just get the result the file is invalid.

the correct format of date is "2011-03-13"(YYYY-MM-DD).

yyyy-mm-dd An easy method would be to do this on one line so that you can play around with the date and the regular expression and learn quickly.

I would use Using a regular expression to parse dates is not a good idea.

If you want to set an error code, you need to add: END But then you would need to check the exit status of each awk that sets it, and you don't do that either.

This question got posted twice: there are some extensive answers at: Subsequent threads have come up with quite a fun technique for this kind of thing: (1) pick out the year, month and day from the date. I think it prints header as Aug 2015, but if it heads like 10 2015 you get a mm that can match a dd.

If the grep returns anything, then that day number happened in that month of that year. GNU awk also has excellent date features, but plain awk does not.# ------------------------------------------------------------------------- # store day, month and year dd=0 mm=0 yy=0 # store number of days in a month days=0 # get day, month and year echo -n "Enter day (dd) : " read dd echo -n "Enter month (mm) : " read mm echo -n "Enter year (yyyy) : " read yy # if month is negative (try this code: DATE=”$*”

If the grep returns anything, then that day number happened in that month of that year. GNU awk also has excellent date features, but plain awk does not.# ------------------------------------------------------------------------- # store day, month and year dd=0 mm=0 yy=0 # store number of days in a month days=0 # get day, month and year echo -n "Enter day (dd) : " read dd echo -n "Enter month (mm) : " read mm echo -n "Enter year (yyyy) : " read yy # if month is negative (try this code: DATE=”$*”[[ “$” ! ([ /.-])(19|20)[0-9][0-9])|(([12][0]|[01][1-9]|2[1-8])? Please clarify your specific problem or add additional details to highlight exactly what you need.As it's currently written, it’s hard to tell exactly what you're asking.You really do not have to run 17 awk processes to deformat one line of text. Also, RETNCODE appears to be intended to be exit status.