Formatting date strings in a file with linux bash shell

后端 未结 3 1231
甜味超标
甜味超标 2021-01-23 21:33

When I cat the file an example of the output format is:

ok: servername Mon May 23 00:00:00 EDT 2018
ok: servername Thu Jul 16 00:00:00 EDT 2019

3条回答
  •  [愿得一人]
    2021-01-23 21:55

    When performance matters. Put this in script.awk:

    BEGIN{ 
      m["Jan"]="01"; m["Feb"]="02"; m["Mar"]="03"; m["Apr"]="04"; 
      m["May"]="05"; m["Jun"]="06"; m["Jul"]="07" # to be completed
    }
    {
      print $1, $2, m[$4] "/" $5 "/" $8
    }
    

    Usage: awk -f script.awk logfile

    Output:

    ok: servername 05/23/2018
    ok: servername 07/16/2019
    

提交回复
热议问题