0

How do I change date/time format from yyyymmddHHMMss to dd/mm/yyyy HH:MM:ss

which is displayed as an output (eg. JOBNAME1 STARTED AT 20180904152402)

from a command...

grep JOBNAME1 | sed -e s/|/ /g | awk {print $3,$7,$8,$9} |sort -r -k 4
2
1
d='\([[:digit:]]\{2\}\)'
sed "s|$d$d$d$d$d$d$d|\4/\3/\1\2 \5:\6:\7|g"

So for your code:

d='\([[:digit:]]\{2\}\)'
awk -F'|' '/JOBNAME1/ {print $3,$7,$8,$9}' | sort -rk 4 |
  sed "s|$d$d$d$d$d$d$d|\4/\3/\1\2 \5:\6:\7|g"
0

Painfully ugly awk method:

echo JOBNAME1 STARTED AT 20180904152402 | awk '{$4=substr($4,7,2)"/"substr($4,5,2)"/"substr($4,1,4)" "substr($4,9,2)":"substr($4,11,2)":"substr($4,13,2); print}'
1
  • Yay....it worked...thanx alot for your help.... – Colin Sep 11 '18 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.