Operating System - HP-UX
1830899 Members
2017 Online
110017 Solutions
New Discussion

Re: Grep/Awk functionalty request

 
SOLVED
Go to solution
Dave Walley
Frequent Advisor

Grep/Awk functionalty request

Hi.

I am looking for your assistance once again.

This time I need to extract from a file the last field regardless of whether it is the fourth, fifth or sixth fields, for example

1679 <****** DWDW COPY VWC87.
1788 CR362 * HGHT HTYG COPY VW4B0.
1793 <** JHGF DERE HGFDE GGG COPY VW4C8.

in this example I would need VWC87., VW4B0. and VW4C8. returned.

Can anybody help please.

Thanking you.

Dave
why do i do this to myself
6 REPLIES 6
Rainer_1
Honored Contributor
Solution

Re: Grep/Awk functionalty request

here the solution:
awk '{print $NF}'
Andreas Voss
Honored Contributor

Re: Grep/Awk functionalty request

Hi,

simply use:
awk '{print $NF}' file

Regards
Andreas Voss
Honored Contributor

Re: Grep/Awk functionalty request

Hi,

simply use:
awk '{print $NF}' file

Regards
Stefan Schulz
Honored Contributor

Re: Grep/Awk functionalty request

Try awk '{print $NF}' yourfile. $NF is the last field of every line in yourfile. The whitspace is the default field seperator. If you want to use another field seperator use awk -F: .... (to use ':' as field seperator).

Hpe this helps.

Regards

Stefan
No Mouse found. System halted. Press Mousebutton to continue.
federico_3
Honored Contributor

Re: Grep/Awk functionalty request

Try:


cat your_file | awk '{print $NF}'


federico
Ralph Grothe
Honored Contributor

Re: Grep/Awk functionalty request

Maybe a superfluous addition,

you can do integer arithmetic with the awk qualifiers like NR, NF.
Sometimes some output produces inconsistent (or rather unpredictable) numbers of fields, but you know that the wanted field is always say n-2

awk '{print $(NF-2)}' /your/file/to/parse
Madness, thy name is system administration