[PLUG] gawk: repeating a field in printed output

Rich Shepard rshepard at appl-ecosys.com
Fri Jun 15 15:17:48 PDT 2018

   In the data files each line consists of a date and 24 numeric values. I
need to convert this "wide" format to a "long" format in which each line has
a date, hour (added in the script), and value. The test version of the script

BEGIN { FS="," }
   { print $1, "00:00", $2"\n"
       $1, "01:00", $3"\n"
       $1, "02:00", $4"\n"

   When run using the two line test file attached, gawk tells me I have a
syntax error at the second and third instances of $1.

$ gawk -f wide2long.awk test.dat > out.dat
gawk: wide2long.awk:9:       $1, "01:00", $3"\n"
gawk: wide2long.awk:9:         ^ syntax error
gawk: wide2long.awk:10:       $1, "02:00", $4"\n"
gawk: wide2long.awk:10:         ^ syntax error

   I have not found the proper syntax in my awk reference book or online. A
pointer to a reference or an explanation of the correct syntax is needed.

-------------- next part --------------

More information about the PLUG mailing list