[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 12:09:06 GMT

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).

This is discussed in the gawk documentation, as well.


In article <address@hidden>,
Ian Macdonald <address@hidden> wrote:
>On Thu 14 Feb 2002 at 04:24:39 +0000, you wrote:
>> I tried:
>> export IFS=:
>> grep eric /etc/passwd |awk '{print $5}'
>> still not working. I'm just trying to print 5th field from /etc/passwd 
>> that will show users full name.
>> Maybe You know different way of doing this, if so please let me know.
>> Thanks again for Your time.
>How about changing the field separator in awk, rather than in bash?
>You could also so away with the grep while you're at it:
>    awk '{FS=":"; if ($5 ~ /eric/) {print $5}}' /etc/passwd
>Ian Macdonald               | Today is a good day for
>address@hidden             | information-gathering.  Read someone else's
>                            | mail file. 
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd.     address@hidden
P.O. Box 354            Home Phone: +972  8 979-0381    Fax: +1 530 688 5518
Nof Ayalon              Cell Phone: +972 51  297-545    (See www.j2.com)
D.N. Shimshon 99785      ISRAEL

reply via email to

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