0

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.

Example:

$ cat date.txt 
Mon Apr 8 21:00:42

-- expected o/p

Mon Apr 8 21:00:42
pLumo
  • 22,565
Ramkumar
  • 113
  • 1
    hm, I don't see how you convert 21:00:42 to 00: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

1 Answers1

1

You can use 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.

pLumo
  • 22,565