Computing.Net > Forums > Unix > awk to print last parameter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk to print last parameter

Reply to Message Icon

Name: jbeaudoi
Date: April 6, 2005 at 03:05:39 Pacific
OS: Win XP
CPU/Ram: 1024
Comment:

Hi could anyone help me print out the last parameter of a line usd=ing awk and a field delimiter?

For example...
Input : Dir/dir/dir/file
awk -F / {print last parameter}

I can't use print $4 since I don't know how many subdirs there are.

Thanks.

Regards,

Jean-Philippe Beaudoin



Sponsored Link
Ads by Google

Response Number 1
Name: jbeaudoi
Date: April 6, 2005 at 03:21:02 Pacific
Reply:

No need to reply. Just got the solution myself.
nawk -F / '{print $NF}'

:-)

Jean-Philippe Beaudoin


0

Response Number 2
Name: gurubit
Date: April 6, 2005 at 03:33:37 Pacific
Reply:

awk provides NF for the number of fields. So it will give you the integer for the number of fields on a line.

Use as below:

awk -F/ '{print $NF}' <filename>

Hope it helps,
Rajesh


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


find'em: search.sh Exiting 2 scripts at once...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: awk to print last parameter

getting awk to print name of file www.computing.net/answers/unix/getting-awk-to-print-name-of-file-/7206.html

How to print columns from file www.computing.net/answers/unix/how-to-print-columns-from-file/4764.html

Printing last few pages (or lines) of a www.computing.net/answers/unix/printing-last-few-pages-or-lines-of-a-/2268.html