In Unix i have a file which has information like below
$ cat date.txt Mon Apr 8 21:00:42
I Need to convert this as 2019-04-09 00:29:22.
2019-04-09 00:29:22
Example:
-- expected o/p
Mon Apr 8 21:00:42
21:00:42
00:29:22
You can use date:
date
date -d "Mon Apr 8 21:00:42" "+%Y-%m-%d %H:%M:%S"
or
date -d "Mon Apr 8 21:00:42" "+%F %X"
For all lines of a file:
xargs -a date.txt -I{} date -d "{}" "+%F %X"
See man date for the FORMAT specification.
man date
21:00:42
to00:29:22
or is it just a bad example ? also your expected o/p is the same as the input. Please fix that. – pLumo Apr 09 '19 at 09:14