Search code examples
timeawklineepoch

AWK command to change epoch time to date and list epoch on same line


So right now I have:

echo -n "Enter Path (or File if in directory) to Convert: " ; read FILE ; cat $FILE | awk '{print strftime("%c",$1)} {print}'

This prints the following, when a file or path is entered to be converted:

Tue 04 Dec 2012 09:48:43 PM PST
1354686523
Wed 05 Dec 2012 09:47:38 PM PST
1354772858
Thu 06 Dec 2012 09:47:39 PM PST
1354859259
Fri 07 Dec 2012 09:46:08 PM PST
1354945568

The above is just an example date. This is perfect, but how do I get this to be on the same line? So it shows each date in the file like this:

Tue 04 Dec 2012 09:48:43 PM PST  --  1354686523
Wed 05 Dec 2012 09:47:38 PM PST  --  1354772858
Thu 06 Dec 2012 09:47:39 PM PST  --  1354859259
Fri 07 Dec 2012 09:46:08 PM PST  --  1354945568

Thanks a lot!!


Solution

  • You could try:

    awk '{ printf "%s -- %s\n", strftime("%c",$1), $0 }' file