Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

time

epoch

awk

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

like image 224
user1893360 Avatar asked Oct 30 '25 18:10

user1893360


1 Answers

You could try:

awk '{ printf "%s -- %s\n", strftime("%c",$1), $0 }' file
like image 175
Steve Avatar answered Nov 01 '25 11:11

Steve