[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IFS system variable

From: Aharon Robbins
Subject: Re: IFS system variable
Date: Thu, 14 Feb 2002 20:00:12 +0200

If eric's entry in the password file is not the first one, the code as
you sent it will work; the assignment changes FS for subsequent records.
But it's not right for the entire file; in particular, the first record
is split using the default value of FS.

Unix awk indeed used to work the way you wrote the program: if you
changed FS before mucking with the fields, the record would be split
with the new FS, but these semantics are just plain wrong and the Bell
Labs awk has been fixed for a long time, as has the POSIX standard.


> Date: Thu, 14 Feb 2002 09:36:02 -0800
> From: Ian Macdonald <address@hidden>
> To: Aharon Robbins <address@hidden>
> Cc: address@hidden
> Subject: Re: IFS system variable
> On Thu 14 Feb 2002 at 12:09:06 +0000, you wrote:
> > That awk code won't do it, use:
> > 
> >     awk -F: '$5 ~ /eric/ { print $5 }' /etc/passwd
> > 
> > Fields are split (conceptually) as soon as the record is read,
> > changing FS in the middle doesn't work on a correct POSIX awk
> > (such as gawk or mawk or recent Bell Labs awk).
> I tested my one-liner on gawk before mailing the suggestion.
>         awk '{FS=":"; if ($5 ~ /eric/) {print $5}}' /etc/passwd
> works for me. As a matter of fact, so does:
>         awk --posix '{FS=":"; if ($5 ~ /eric/) {print $5}}' /etc/passwd
> Ian
> -- 
> Ian Macdonald               | It isn't easy being the parent of a
> address@hidden             | six-year-old.  However, it's a pretty small
>                             | price to pay for having somebody around the
>                             | house who understands computers. 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]