Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Edited again to add more clarity. Hopefully. ;)

I ran the command # cat * |grep -P '\d+\.\d+\.\d+\.\d+' on a directory containing a bunch of iptables configuration files, in order to pull out all of the lines which had something that looked like an IP address on them. Given that most of the lines were of the form

ADMIN__SANDRO_DESK="123.456.78.90"   #  ilcylic Desktop

my first thought was to then |awk {print $1;} to eliminate the trailing comments, but then shortly realised that eliminated a bunch of stuff I actually wanted.

In then attempting to see what I would be eliminating, I tried to create a regex for grep -P that would show me lines which had, roughly, ^[one or more non-whitespace chars, which also do not form an IP address][one or more whitespace chars][zero or more chars][an IP address]

The first part proved to be the most difficult. How would one say "a string of one or more non-whitespace chars, which are also not an IP address" since, of course, an IP address is a string of one or more non-whitespace chars?

Thanks in advance, Monks. :)

Edited to add some examples (examples also edited):

So, if I were to cat a file and run it past grep -P 'My_Regex', it would not match lines of the form

ADMIN__SANDRO_DESK="123.156.78.90"   #  ilcylic Desktop

but would match lines like

# ADMIN__SANDRO_DESK="123.156.78.91"   #  ilcylic Desktop (old)

or

# 06/06/15    SR    Chgd SANDRO 121.123.154.99

or

ADMIN__SANDRO_DESK = "123.156.78.90"


In reply to Seeker of Regex Wisdom (strings which don't form specific patterns) by ilcylic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-03-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found