bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: About gawk! Is this a bug???


From: Kenny McCormack
Subject: Re: About gawk! Is this a bug???
Date: 25 Mar 2002 16:26:51 -0600

In article <address@hidden>,
Aharon Robbins <address@hidden> wrote:
>> From: "º£Ìì" <address@hidden>
>> To: address@hidden
>> Cc: address@hidden
>> Subject: About gawk! Is this a bug???
>>
>>
>> Hi,
>>
>>   I am sorry to trouble you, i have a question!
>>   Just look that the things below:
>>
>> --------------------------------------------------
>> address@hidden cat /etc/passwd
>> root:x:0:0:root:/root:/bin/bash
>> bin:x:1:1:bin:/bin:
>> daemon:x:2:2:daemon:/sbin:
>>
>> address@hidden gawk '{FS="/"};{print $NF}' /etc/passwd
>> root:x:0:0:root:/root:/bin/bash
>> bin:
>> sbin:
>>
>>   Why the first line of the file "/etc/passwd" is still 
>> "root:x:0:0:root:/root:/bin/bash" ?
>>   Is it a bug of ver3.0.4 OR just my falt? What can I do about this? Please 
>> help me! Thank U very much! (^o^)
>>
>
>See the gawk.info file, node `Field Splitting Summary' which has a
>subheading labelled `Setting FS does not affect the fields.'  The
>short answer is to use
>
>       BEGIN { FS = "/" }
>       { print $NF }
>
>or to use
>
>       awk -F/ '{ print $NF }' /etc/passwd
>
>Arnold

Or, if you absolutely must do it this way (that is, change FS on the fly),

{FS="/";$0=$0;print $NF}

Obviously, silly in the instant case, but can be applicable in other
situations (such as one recently posted on comp.lang.awk, where the guy
wanted to chagne FIELDWIDTHS on the fly, based on the data)



reply via email to

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