[PLUG] awk syntax
Ken Stephens
kens at cad2cam.com
Thu May 24 18:25:47 UTC 2012
Rich Shepard wrote:
> I'm re-reading the ORA 'sed& awk' 2nd edition because I need to modify
> data files (>130K lines in one and>45K lines in another). Should be a
> simple script but I'm getting a syntax error trying to define the OFS.
>
> Here's a line of the data file:
> 'D-1'|'2007-12-12'|'Ag'|0.000|
>
> Since fields in the data file are delineated with '|'. I define FS = '|'
> in the BEGIN section, but awk doesn't like me to also define OFS there:
>
> awk: ./add-non-detect.awk:7: BEGIN { FS = "|" OFS = "|" }
> awk: ./add-non-detect.awk:7: ^ syntax error
>
> There's no explicit example in the book, only statements that the default
> output field separator is a space, and that's applied by putting a comma
> after the field variable. What have I missed?
>
> Rich
>
>
>
Rich,
The page, http://www.gnu.org/software/gawk/manual/gawk.html, shows an
example of two variables supplied in a "BEGIN" statement:
$awk 'BEGIN { OFS = ";"; ORS = "\n\n" }
Looks like a semicolon is the separator here.
Ken
More information about the PLUG
mailing list