Solved

how to grep these two IP address

Posted on 2014-04-15
6
1,682 Views
Last Modified: 2014-04-18
Hi,

I have two IP addresses

2/.2/.2./2

or

1/.1/.1/.1

I want to grep for both

I tried

grep -E -o "2/.2./2./2|1/.1/.1/1"  *
grep -E "2/.2./2./2|1/.1/.1/1"  *

Without success (the above commands are not pulling the correct IP)

Any ideas? Thanks.
0
Comment
Question by:NYGiantsFan
6 Comments
 
LVL 14

Expert Comment

by:sentner
ID: 40002037
Why do you have forward slashes in there?  Replace those with backslashes (\) instead and you should be ok (presuming that the source file itself doesn't have slashes in there for some reason).
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40002040
Is grep different? I thought the escape character is \

1\.1\.1\.1
0
 
LVL 21

Expert Comment

by:Mazdajai
ID: 40002127
grep -iP '2\.2.\2\.2|1\.1\.1\.1'  *

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 40002333
The bare grep for 1.1.1.1 will also match 221.1.1.123, because it doesn't care what comes before the first "1" or after the last.  In know this is an artificial example, but it can still be a problem with real IP addresses - e.g. if you are looking for 192.168.0.10, the pattern '192\.168\.0\.10' will also match 192.168.0.102.

To get round that, add the "-w" option, so that grep will only match strings on word boundaries (e.g. the "\.1" at the end of the pattern is followed by a punctuation character, or a space, or the end of a line).

Yo also need the "-E" to use extended regular expressions (for the "|")

So, the test becomes

     grep -Ew '1\.1\.1\.1|2\.2\.2\.2' *
0
 

Author Closing Comment

by:NYGiantsFan
ID: 40004824
It worked without the -w
0
 
LVL 19

Expert Comment

by:simon3270
ID: 40009226
It works now, but it may fail in the future with different IP addresses and different data to be searched!

Thanks for the points!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question