I understand sub(), gsub(), and substr() but have difficulty figuring out
how to use any or all to modify a field's contents.

   Context: data files have variable numbers of fields per record; most of
these fields represent measured values as integers or (more often) as
floating point numbers. When a value is below the laboratory's method
detection limit they report the value with '<', '< ', or '-' preceeding the
floating point number. I want to strip off the leading symbol (with any
following white space) and retain the floating point number as the field's
content.

   It seems that sub() should do the job when I understand how to present the
arguments to the function. The syntax is sub(regex, replacement [, target]).
Not knowing if I can have if/elseif/elseif/else in the regex position my
initial approach is to use four calls to the function; e.g.,

        sub(/\</,"") or sub(/\< /,"")

Would these leave the remainder of the field's contents intact? gsub()
probably adds no more capabilities to solving this problem than does sub().
Not sure if substr() is really appropriate here.

   I've read the two post-"The AWK Book" books I have and understand the
syntax but not how to apply the functions to achieve what needs to be done.

   This is just one issue that I need to grok while developing this generic
data cleaning program.

Rich
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to