I am always surprised that people use sed and awk instead of perl.
But first, using both grep and awk with an extra option, don't be shy about it:
ifconfig | grep 'inet addr:' | awk {'print $2'} | awk -F: {'print $2'} | grep -v '127.0.0.1'
replace awks with perl:
ifconfig | grep 'inet addr:' | perl -F\\s\|: -ane 'print "$F[2]\n"' | grep -v '127.0.0.1'
replacing greps within a single perl script:
ifconfig | perl -F\\s\|: -ane 'next if !/^inet addr:/ or /127\.0\.0\.1/; print "$F[2]\n"'
and finally just using the power of the perl regular expression:
ifconfig | perl -ne 'next if !/inet addr:(?<ip>[0-9.]+)/ or $+{ip} == "127.0.0.1"; print "$+{ip}\n"'
Gerard ONeill
source share