Filter ifconfig with Perl

Written by chenhow on October 7, 2008 – 8:55 am - 109 views

Linux/Unix: Below is the commands to filter ifconfig to show only the eth0 IP address in Linux.

Perl Script:

Option 1

eth0 | grep “inet addr”| awk {’print $2′} | perl -e ‘while(<>){ ($a,$b)=split/:/; print $b; }’

Option 2

ifconfig eth0 | grep “inet addr” | perl -e ‘while (<>) { ($inet, $addr, $ip, $others) = /(\w+)\s+(\w+):(\S+)\s+(.*)/; print $3.”\n”;}’

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • TwitThis
  • Reddit
  • LinkedIn
  • Live

Tags:


  • keng woh~ for wat purpose then?
  • err..... to capture IP only lor

    Sweat~
blog comments powered by Disqus