[nmglug] awk pattern found

Edward F. Brown ebrown at lanl.gov
Fri Jan 20 17:37:32 PST 2006


Interesting question, and I didn't understand Karl's explanation until
reading up a little myself.  So a 'match' in awk is a whole 'record', $0,
usually a line, unless you change the record separator (RS).  And Karl's
suggestion was that individual 'fields' (typically words if the field
separator (FS) is whitespace) in the matched line could then be tested
against the regex to narrow it down further.  Which works if the match is
contained within a field, when it might span fields.  Or a match could
just be a substring of a field.  Basically, it looks like the answer to
your question is that there isn't a variable that holds just the matched
part of the record like there is in perl.

-Ed


On Fri, January 20, 2006 5:32 pm, Karl Hegbloom said:
> On Fri, 2006-01-20 at 11:26 -0700, Andres Paglayan wrote:
>> does anybody knows which variable in awk will hold the pattern found?
>
> I just typed "info gawk", and found it fairly quickly...
>
> $0 is the input line, and a regexp constant by itself means $0 ~ /expr/.
> The line is tokenized on whitespace (probably $IFS) and each token is
> $1, $2, etc, so you can test $1 ~ /expr/ if you like.  It does not look
> like Awk supports capturing of matched subexpressions as in Sed or Perl.
>
> --
> Karl Hegbloom <karlheg at laclinux.com>
> Los Alamos Computers, Technical Support
>
>
> _______________________________________________
> nmglug mailing list
> nmglug at nmglug.org
> http://www.nmglug.org/mailman/listinfo/nmglug
>





More information about the nmglug mailing list