On Thu, May 24, 2012 at 11:36 AM, Rich Shepard <[email protected]> wrote:
>   I obviously do not grok the use of OFS (Output Field Separator) and how to
> specify its use in a print statement. Here's my complete script:
> ------------------------------------------------------------------------------
> #! /usr/bin/awk -f
>
> # add-non-detect.awk -- Add both an indicator digit (0 = quantified, 1 = <RL)
> #                       and bounds to non-detected quantities.
> # Fields: site, sampdate, param, quant; last char is \n.
>
> BEGIN { FS = "|"; OFS = "|" }
>
> # Detected quantity
> $4 !~ /-.*/ { print $1 $2 $3 $4 "0" $4 $4 }

You would only need the OFS if it was different from the FS like this simple
example:
[lbrigman-lbrigman_tot_area51@lbrigman-desktop kernel]$ awk 'BEGIN{
FS=":";OFS="|";} {print $1,$NF}' /etc/passwd | head -10
root|/bin/bash
bin|/sbin/nologin
daemon|/sbin/nologin
adm|/sbin/nologin
lp|/sbin/nologin
sync|/bin/sync
shutdown|/sbin/shutdown
halt|/sbin/halt
mail|/sbin/nologin
news|

Note the print field,field.  The comma is replaced by the OFS.

>
> # Non-detected quantity
>
> $4 ~ /-.*/ { print $1 $2 $3 $4 "1" "0" $4 }
>
> -------------------------------------------------------------------------------
>
> And here are three lines of data:
>
> 'D-1'|'2007-12-12'|'Ag'|0.000|
> 'D-1'|'2007-12-12'|'Al'|0.106|
> 'D-1'|'2007-12-12'|'CO3'|-1.000|
>
>   The output from the script is:
>
> 'D-1''2007-12-12''Ag'0.00000.0000.000
> 'D-1''2007-12-12''Al'0.10600.1060.106
> 'D-1''2007-12-12''CO3'-1.00010-1.000
>
>   Not only are the pipe symbols missing, but I see the logic needs
> correcting, too. I'll work on that after I learn how to properly specify OFS
> and the print statements.
>
> Rich
>
>
>
> _______________________________________________
> PLUG mailing list
> [email protected]
> http://lists.pdxlinux.org/mailman/listinfo/plug
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to