Reputation: 59
How to convert any date to YYYYMMDDHHMMSS
using unix shell script?
It is not specific date it may any date. how to convert it?
example date format is: 20110101050603
Thanks Puspa
Upvotes: 1
Views: 18708
Reputation: 5017
DATE = "15 Jun 2015 10:10:10"; date -d"$DATE" +%Y%m%d%H%M%S
Output :-
20150615101010
More on Dates
Note this only works on GNU date.
I have read that:
Solaris version of date, which is unable to support -d can be resolve with replacing sunfreeware.com version of date.
Update:-
Use ls
command to find all files and use grep
command for all files.
ls | grep "[0-9]{14}"
grep
command also accepts regular expression.
But it won't validate your file accurate. For example, if a file name is 20151835101010
, then it will validate this file. But actually month and date both are wrong.
So my suggestion is to write a shell script to identify valid file name and find oldest of them by processing one by one.
Upvotes: 3