how to grep for an IP address

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Elizabeth H
    New Member
    • Jan 2011
    • 19

    how to grep for an IP address

    I wanted to grep the IP address from this following exception. What is the easiest way to do this?

    "var=something. something.somth ing.Exception : The IP xx.xxx.x.xxx cannot be used"


    I want to grep the IP address from this string and store it in a different variable. Do i just use the regular regex pattern to grep an IP address or is there an easy way
  • pawanrpandey
    New Member
    • Feb 2007
    • 14

    #2
    One simple way would be to use regex like:
    Code:
    my $var = "something.something.somthing.Exception : The IP xx.xxx.x.xxx cannot be used";
    $var =~ /(\d+\.\d+\.\d+\.\d+)/ ;
    print "IP Address is $1 \n";

    Comment

    Working...