I have a file with date and time on a couple thousand lines.
I need to convert:
2019/08/02-01:23:50+0000
To:
02/Aug/2019-01:23:50 +0000
I so far have
th=`grep -o '\[.*\]' test.txt | sed 's/\"//g' | head -1
echo $th | date -d +'%Y/%b/%d-%T'
date: invalid date ‘+%Y/%b/%d-%T’
How can I read in the date and format it?
Something like this:
In one line or
First step is to extract 2019/08/02 and convert 08 to Aug then with multiple separators extract all fields and
printf
with the format we want. Tricky thing here, passingshell
variable toawk
(fill free to remove\n
inprintf
format)