G'day ilcylic,
While it may be possible to use 'grep -P ...', I suspect using 'perl ...' (on the command line) would be a lot simpler.
Regexp::Common provides often-used regexes;
Regexp::Common::net has regexes for IP addresses.
Using this module, I'd eliminate lines matching /^$RE{net}{IPv4}/ first;
then attempt to match /^\S+\s+.*?$RE{net}{IPv4}/.
For use on the command line:
$ perl -MRegexp::Common=net -wnE '/^$RE{net}{IPv4}/ and next; /^\S+\s+
+.*?$RE{net}{IPv4}/ and say'
127.0.0.1aaa 127.0.0.1
256.0.0.1aaa 127.0.0.1
256.0.0.1aaa 127.0.0.1
aaa 127.0.0.1
aaa 127.0.0.1
Having tested that solution, I noticed your update with examples.
For IPv4, all of the octets should be in the range 0-255.
I suspect you generated quick-and-dirty examples (by running along the number keys) which has produced invalid IP addresses. Changing 456 to 156 and 654 to 154, the same one-liner matches the way you want:
$ perl -MRegexp::Common=net -wnE '/^$RE{net}{IPv4}/ and next; /^\S+\s+
+.*?$RE{net}{IPv4}/ and say'
ADMIN__SANDRO_DESK="123.156.78.90" # ilcylic Desktop
# ADMIN__SANDRO_DESK="123.156.78.90" # ilcylic Desktop
# ADMIN__SANDRO_DESK="123.156.78.90" # ilcylic Desktop
# 06/06/15 SR Chgd SANDRO 121.123.154.99
# 06/06/15 SR Chgd SANDRO 121.123.154.99
-
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.
|