Monday, June 10, 2013

How to filter only the first Row of awk Output?



For e.g., I need the ping output of where a particular dns resolves to. The problem is I get 2 lines of same text to where this DNS is getting resolved. I need to filter this so that I get just a single line. 

`ping -t 1 abc.mydomain.com | grep "elb." | awk ' { print $2 } '`

The above command outputs 2 lines of same text.. 

mylb.elb.amazonaws.com
mylb.elb.amazonaws.com

To overcome this problem, i modified this to: 

`ping -t 1 abc.mydomain.com | grep "elb." | awk ' { print $2; exit(0); } '`


No comments:

Post a Comment