1833907 Members
2336 Online
110063 Solutions
New Discussion

Awk Help Pls!

 
SOLVED
Go to solution
rveri
Super Advisor

Awk Help Pls!

Hi All ,

How to print the last string from a line , with the help of awk.

Please help asap:

Suppose I have several line like:

-----
abc def ghi jkl mno pqr stu vwx yz=10001
abc eed fsf sffs yz=10002
zfd sf sfs sf ssfs sfs fsf yz=10012
...
-----


I want to print yz value only.

How can I do that .

Thanks,
6 REPLIES 6
Patrice Le Guyader
Respected Contributor
Solution

Re: Awk Help Pls!

Hi,

Try like this :

awk '{print $NF}'

Hope this helps
Kenavo
Pat
Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.
Peter Godron
Honored Contributor

Re: Awk Help Pls!

rveri,
to get the 10001, 10002 etc. you can use
awk '{print $NF}' | awk -F'=' '{print $NF}'

but I am sure this can be combined into one, but I am not an awk expert.
Peter Godron
Honored Contributor

Re: Awk Help Pls!

Hi again,
please no points for this post!

You can drop the first awk of my previous answer and get the same results.
Sam can be done with:
cut -d'=' -f2 file
rveri
Super Advisor

Re: Awk Help Pls!

Many Thanks Patrice,

This is working perfectly,
10 points.
john korterman
Honored Contributor

Re: Awk Help Pls!

Hi,

$ awk -F= '{print $NF}' < infile

should also work.

regards,
John K.
it would be nice if you always got a second chance
rveri
Super Advisor

Re: Awk Help Pls!

Thanks All.