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
I would like the format to be something like
ok: servername 05/23/2018
ok: servername 07/16/2019
I need to use the Linux bash shell to do it. If any one could help me I be very grateful.
With GNU
date
, you can specify an input file containing all your date strings; combined withcut
andpaste
:Output:
This uses process substitution to build a temporary input file for
date -f
, and forpaste
to build a new output file.According
man date
, the command is able tovia
--date
or-d
. So if you store your values in a variableyou could use something like
to reformat the timestamp.
For more information you may have a look into Convert date formats in bash.
When performance matters. Put this in
script.awk
:Usage:
awk -f script.awk logfile
Output: