Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Match IP from 2nd line and Print Hostname from 1st line

by ArifS (Beadle)
on Aug 01, 2016 at 13:33 UTC ( [id://1168920]=note: print w/replies, xml ) Need Help??


in reply to Re: Match IP from 2nd line and Print Hostname from 1st line
in thread Match IP from 2nd line and Print Hostname from 1st line

It worked-
(\w+.+)
OUPUT
ip 10.1.1.1 goes with host name HOSTNAME-1A_1ST ip 10.1.1.2 goes with host name HOSTNAME-1B_2ND ip 10.3.1.1 goes with host name HOSTNAME-2A_1ST ip 10.3.1.2 goes with host name HOSTNAME-2B_2ND
Thank you Corion.

Replies are listed 'Best First'.
Re^3: Match IP from 2nd line and Print Hostname from 1st line
by Marshall (Canon) on Aug 01, 2016 at 17:31 UTC
    In this case your modified expression works fine because there aren't any trailing blanks after the Hostname. If that happened, something like "HOSTNAME-1A_1ST   " your expression would also pick up those extra spaces. To prevent that, you could use a character set, like ([\w\-]+) That essentially adds "-" to the \w character set.

    Update: There is more than one way to write the regex. Another possibility would be (\S+) Changing one character (\w to \S) does a lot. That would match any non-whitespace character. So if some weirdo thing like "*" showed up, it would also be included. What you choose to implement depends both upon your actual data and personal preference.

      That helps. Some good tips! Thank you Marshall.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1168920]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-29 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found