< Browse > Home / Programming / Blog article: Filter ifconfig with Perl

| RSS

Filter ifconfig with Perl

October 7th, 2008 | 6 Comments | Posted in Programming

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”;}’

Related Posts
  • No Related Posts
Leave a Reply 1113 views, 2 so far today |
Related Posts
  • No Related Posts
  • http://lockgoh.blogspot.com Lock

    keng woh~ for wat purpose then?

  • http://lockgoh.blogspot.com Lock

    keng woh~ for wat purpose then?

  • http://blog.chenhow.net chenhow

    err….. to capture IP only lor

    Sweat~

  • http://blog.chenhow.net chenhow

    err….. to capture IP only lor

    Sweat~

  • http://lockgoh.blogspot.com Lock

    keng woh~ for wat purpose then?

  • http://blog.chenhow.net chenhow

    err….. to capture IP only lor

    Sweat~