Re: quick awk/cut question

From: Jef Lee (jef.lee@ITVISION.COM.AU)
Date: Thu Jul 25 2002 - 04:41:27 EDT


Try

awk 'BEGIN {FS = "/"} {print $NF }' file.txt

That way the AWK program will know what a field
separator is BEFORE it tries to process any
line.

Jef...

-----Original Message-----
From: Barry Deevey [mailto:Barry.Deevey@SEFAS.CO.UK]
Sent: Thursday, 25 July 2002 4:34 PM
To: aix-l@Princeton.EDU
Subject: quick awk/cut question

Hi everybody,

I'm trying to extract the last field from a file that has a varied number of
fields. I'm trying

awk '{FS = "/" ; print $NF }' file.txt

But the above returns the whole of the first line, and then the last field
from the remaining lines. I know I'm doing something daft, but I just can't
see what. Also, I would have prefered to use the cut command, but with the
input file having a varied number of fields I couldn't get it to work.

Thanks in advance for any help provided, its much appreciated.

Best Regards

Barry



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:05 EDT