I am trying to format some text from a file using awk.
The requirement is to replace the 3rd field of a colon-seperated file (:) representing epoch time with a formatted string representing the human-readable time in the follow format: DD/MM/YYYY
Here is an example file:
abc:$3$wHe$JKAP1Ry.CAcEGhD0J7SGVl.AMg.0:1427135400:0:120:7:30:: rst:$6$3WWbfvblr6FF92R5/n3mLdlSkARgfRm1:1427293800:0:40:7:30:: xyz:$1$xuTkkle203F$df.ixcn/mcuFIO90lndn:1420478400:0:90:7:30:: def:$4$vid2003mDEOF$dc2.Rkdlkfdiw8/cib6:1389547200:0:120:7:30:: ab:*$5P1wHeEG$JKA2ya.ikol30.de/ldiv.230:1449771300:0:120:7:30:: xy:$1k3lc930vs.lskdie/sldiemDIIsdk193n:1429995693:0:50:7:30:: xyy:*$tkwsMt972w.Csrl5jr.23nsoijsleqJK:1429995889:0:120:7:30:: By copying and pasting a one of the values from the 3rd field into the a command using date I have been able to create the desired results:
date -d @1427135400 +"%d/%m/%Y" 23/03/2015 Here is the awk command that I am trying to execute in the script, I have been tweeking the script here and there in hopes to get it to work, but with no luck. Note that $userFound has already stored a single line from the file listed above:
echo $userFound | awk -F':' '{ if ( $2 ~ /^\*/ ) {$2="L"} \ if ($2 ~ /^[^*]/) {$2="P"} \ cmd="date -d @"$3" +\"%d/%m/%Y\"" \ cmd | getline time \ close(cmd) \ } \ END { \ print $1":"$2":"time":"$4":"$5":"$6":"$7":"$8":"$9 \ }' Running the current script, I get the following output:
awk: cmd. line:5: (FILENAME=- FNR=1) fatal: expression for `|' redirection has null string value
(FILENAME=- FNR=1)part, please post the whole thing.