如何将日期/时间格式从 更改yyyymmddHHMMss
为dd/mm/yyyy HH:MM:ss
显示为输出(例如 JOBNAME1 STARTED AT 20180904152402)
从命令...
grep JOBNAME1 | sed -e s/|/ /g | awk {print $3,$7,$8,$9} |sort -r -k 4
答案1
d='\([[:digit:]]\{2\}\)'
sed "s|$d$d$d$d$d$d$d|\4/\3/\1\2 \5:\6:\7|g"
所以对于你的代码:
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"
答案2
丑陋的 awk 方法:
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}'