Regex for plucking out IPs and CIDRs from text file?
Hello to the unix.com community.
I have a mess of text. What I would like to do I pluck out IP addresses and CIDR notations only.
I thought I would try something like this
But there are a few problems wit this.
This regex will not print out CIDRs. This is because it's not designed to as I have no idea how to create a regex to match CIDR Notations.
Also this regex will print information I don't want printed. For example. Somewhere in the mess of text there's two strings I wanted printed when searching for IPs and CIDR notations. Lets say those two strings are "1.1.1.1/8 and 2.2.2.2" When running the above command, the output should look like this
However, the output is
What regex would I need to print out only IPs and CIDRs?
The output should look like this
---------- Post updated 07-24-10 at 10:29 AM ---------- Previous update was 07-23-10 at 05:16 PM ----------
Here's where I'm at now
This matches valid IPs and CIDRs such as
However this also match invalid IPs and CIDRs such as
Last edited by TroubleNow345; 07-24-2010 at 11:25 AM..
Reason: Code tags, please!
Here is my sample file data:
My requirement is to have a regex expression that is able to search for visible starting string "SSLInsecureRenegotiation Off" between strings "<VirtualHost " and "</VirtualHost>".
In the sample data two lines should be matched.
Below is what I tried but... (5 Replies)
Hello again gentlemen.
I would like to make a shell script to 'optimize' a plain text full of IPs.
Let's suppose to have this text file:
1.192.63.253-1.192.63.253
1.0.234.46/32
1.1.128.0/17
1.116.0.0/14
1.177.1.157-1.177.1.157
1.23.22.19
1.192.61.0-1.192.61.99
8.6.6.6
I want to... (2 Replies)
I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header.
In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Hi
I am trying to filter some data using awk. I have a statement-
awk 'BEGIN { FS = "\n" ; RS = "" } { if ( $6 = "City: " ) { print "City: Unknown" } else { print $6 } }'`
The $6 values are
City: London
City: Madrid
City:
City: Tokyo
This expression seems to catch all the lines... (4 Replies)
Hi,
Server - MEDIAWIKI - MYSQL - CENTOS 5 - PHP5
I have a database import of close to a million pages into my wiki, mediawiki site,
the format that were left with is not pretty, and I need to find a way to clean this up and present it nicely...
I think regex is the best option as I can... (1 Reply)
Hi Everyone,
I typed a command:
awk '{ print $1}' $LOGFILE | sort | uniq -c | sort -nr > $DEST/a.txt
And I got file a.txt which show
6 1.1.1.1
3 2.2.2.2
2 3.3.3.3
1 4.4.4.4
Just now, I want to get exact ips which has first column > 5 to a file b.txt. In this situation, the... (5 Replies)
I have a large file encoded in Unicode that I need to convert to CSV. In general, I know how to do this by regular expression substitutions using sed or Perl, but one problem I am having is that I need to put a quotation mark at the end of each line to protect the last field. The usual regex... (1 Reply)
Hi,
Please help me write regex for text pattern like
CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3, ...so on
Any advice is Okay!
Thanks in advance. (6 Replies)