Linux shell programing validating date

# This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nix Craft shell script collection (NSSC) # Visit for more information.

Thankfully, when [strings that use the YYYY-MM-DD format] are sorted* in alphabetical order, they are also sorted* in chronological order.

It won't be validated, but you won't know why.

Maybe because of invalid format (not conforming to YYYY-MM-DD), maybe because of an invalid value (2015-02-31). The OP's question was not about value validation, but of format validation.

The date string format is more complex than is easily documented here but is fully described in the info documentation. For numeric months, the ISO 8601 format 'year-month-day' is allowed, where year is any positive number, month is a number between 01 and 12, and day is a number between 01 and 31.

A leading zero must be present if a number is less than ten.

File layout is: Header - Rec_Type|File_name|File_Date Detail - Rec_Type|field1|field2|field3...For one, determination of "valid" dates is non-trivial in regular expressions -- ie.determination that 2015-02-31 is not valid, but 2015-03-31 is.Use grep & tail 3) Check if there is multiple records of header & trailers.Use grep & wc It checks both for the existence of exactly one header and one trailer, AND checks that the record count in the trailer matches the records observed.

Leave a Reply