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

| RSS

Filter ifconfig with Perl

October 7th, 2008 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”;}’

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • MySpace
  • Twitter
Related Posts
  • No Related Posts
Follow Discussion

View Comments to “Filter ifconfig with Perl”

  1. Lock Says:

    keng woh~ for wat purpose then?

  2. Lock Says:

    keng woh~ for wat purpose then?

  3. chenhow Says:

    err….. to capture IP only lor

    Sweat~

  4. chenhow Says:

    err….. to capture IP only lor

    Sweat~

  5. Lock Says:

    keng woh~ for wat purpose then?

  6. chenhow Says:

    err….. to capture IP only lor

    Sweat~

Leave a Reply

blog comments powered by Disqus

World Vision / WWF

World Vision
One Life - Do Something
I support WWF

Subscribe

Follow Me Twitter Follow Me Friendfeed Subscribe RSS to receive content updates in your favorate reader
Follow Me Facebook Follow Me LinkedIn
RSS Subscribe in a reader
RSS Or, subscribe via email:
     

Recent Post

    • [Centos] Kickstart (Unattended) Linux OS installation
    • Singtel Iphone 4 Launching Date
    • Create Bootable USB Drive For Centos Installation
    • PC Server For Research
    • I’m Back Again

Popular Post