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

14,740

You could try:

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

Related videos on Youtube

user1893360
Author by

user1893360

Updated on June 06, 2022

Comments

  • user1893360
    user1893360 almost 2 years

    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!!

  • user1893360
    user1893360 over 11 years
    I'm getting a Syntax error.. if it helps im on XShell (linux terminal)

Related