Tuesday, September 2, 2014

Display the second instance of a word

A quick post to share a handy command that displays the second instance of a word. For this example I was trying to quickly get the IP address for a list of switches by using nslookup and only printing the device name, and it's IP (not other details like dns server).

for x in `cat /tmp/switch.list`; do echo ${x}:; nslookup ${x} | awk '/Address/{i++}i==2'; done