[PLUG] gawk: repeating a field in printed output
Michael Rasmussen
michael at michaelsnet.us
Fri Jun 15 22:38:30 UTC 2018
Having not used awk in 20 years or so my wild ass guess is you need to
add commas at the ends of lines 2 and 3, unless awk treats newlines as
argument separators.
1 BEGIN { FS="," }
2 { print $1, "00:00", $2"\n"
3 $1, "01:00", $3"\n"
4 $1, "02:00", $4"\n"
5 }
And editing the script to add those commas and run on locally generated
test data shows that to be the case.
On 2018-06-15 15:17, Rich Shepard wrote:
> 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
> _______________________________________________
> PLUG mailing list
> PLUG at pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
--
Michael Rasmussen, Portland Oregon
Be Appropriate && Follow Your Curiosity
More information about the PLUG
mailing list