I saw couple of posts (some depends upon date -d $xyz
to verify) but I'm trying to create an until
loop where the user should be re-prompted to enter the value of a date format until it matches the custom date format.
My date format (what I need for Splunk) is m/d/yyyy:h:m:s
or mm/dd/yyyy:hh:mm:ss
which means, if m
(month number) is a single digit lets say 1 for January
, then both 1
or 01
values are possible for date format but 0
or 00
is NOT a valid value. Value range is 01-to->12
or 1-to->12
but not greater than 12.
Similarly, the same rule applies to d
(day number), it can be 01-to->10-to->31
or 1-to->31
but not 00
or more than 31
and all other yyyy
(year), h
(hour), m
(minute), s
(second) part.
What could be a minimal code (obfuscated is fine) to do this verification in BASH? It seems like date -d ???
doesn't provides this custom kind of verification for date/times!
OK, I can write one verifyDateFormatfunc() to do this, but I know there are people who have already written a one-liner / minimal snippet to verify this for sure. grep -f ..
(where bunch of regex are listed line by line for all possible combinations, again the main code will look very minimal if I follow this? as the patterns sitting in -f file
for grep
will be transparent to a user) -or creating a map funcation (based on delimiters) for value ranges?
Possible values:
1/03/2017:23:0:15
02/4/2017:0:1:2
09/05/2017:10:10:0
10/6/2017:12:14:16