0

I want to take time difference of two time stamp but getting an error while passing timestamp variable from shell toawk.

Shell code:

FTIMESTAMP="2015-07-01 12:30:50"
gawk -v FTIMESTAMP=$FTIMESTAMP -v DSECONDS=$DSECONDS -f test.awk /home/abc/TShift.csv 

Error is:

gawk: 12:30:50
gawk:   ^ syntax error

Escaping character is also not working FTIMESTAMP="2015-07-01 12\:30\:50".

I have another timestamp in awk and want to take time difference between them.

cuonglm
  • 153,898
Aashu
  • 771

2 Answers2

2

You need to quote variables to prevent shell from performing split+glob:

gawk -v FTIMESTAMP="$FTIMESTAMP" -v DSECONDS="$DSECONDS" ...

A note that -v var="$shell_var" will expand escape sequences in $shell_var. You need to use ENVIRON or ARGV variables to pass $shell_var as-is from shell to awk.

cuonglm
  • 153,898
0

try either

gawk -v FTIMESTAMP="$FTIMESTAMP" -v DSECONDS=$DSECONDS -f test.awk /home/abc/TShift.csv 

there is a white in $FTIMESTAMP

or in calling shell

FTIMESTAMP="2015-07-01 12:30:50"
export FTIMESTAMP

and in awk's script (in BEGIN { .. } section)

FTIMESTAMP=ENVIRON["FTIMESTAMP"] ;
Archemar
  • 31,554