Formatting date strings in a file with linux bash shell

后端 未结 3 1230
甜味超标
甜味超标 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 22:12

    According man date, the command is able to

    display time described by STRING, not 'now'

    via --date or -d. So if you store your values in a variable

    DATE="Thu Jul 16 00:00:00 EDT 2019"
    

    you could use something like

    date --date="${DATE}" +%m/%d/%Y
    

    to reformat the timestamp.

    For more information you may have a look into Convert date formats in bash.

提交回复
热议问题