[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
is:

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.

Rich
-------------- next part --------------
2006-10-01,10.72,10.70,10.72,10.69,10.66,10.65,10.66,10.66,10.66,10.64,10.64,10.63,10.63,10.64,10.64,10.65,10.68,10.68,10.67,10.68,10.69,10.69,10.69,10.67
2006-10-02,10.67,10.67,10.67,10.67,10.68,10.67,10.68,10.68,10.68,10.68,10.68,10.68,10.68,10.68,10.64,10.64,10.69,10.75,10.74,10.70,10.69,10.71,10.70,10.70


More information about the PLUG mailing list