LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   grep ip adress using wildcards (https://www.linuxquestions.org/questions/programming-9/grep-ip-adress-using-wildcards-4175418086/)

masterav 07-22-2012 10:23 AM

grep ip adress using wildcards
 
Hi,

I need to grep a ip adress from the file mentioned below using wildcards.

The ip adresss can be like this,
10.211.32.3
192.168.1.1
132.213.231.312

the number of octets vaires for each..

-------------------------------

cat fileone

Keyboarders normally indent paragraphs three to five word spaces.based on what they were taught in school.while professionally printed material such as books and magazines generally use smaller indents.[citation needed] The Elements of Typographic Style states that "at least one 10.211.32.3 en [space]" should be used to indent paragraphs after the first,[6] noting that that is the "practical minimum".[7] An em space is the 192.168.1.1 most commonly used paragraph indent.[8] Miles Tinker, in his book Legibility of Print, concluded that indenting the first line of paragraphs increases readability by 7%, on the average.[9] 132.213.231.312

-------------------------------

So my task here is that, i need to get all the ip addresses in the above paragraph...

Thanks in advance..

dmdeb 07-22-2012 10:32 AM

Quote:

Originally Posted by masterav (Post 4735170)
Hi,

I need to grep a ip adress from the file mentioned below using wildcards.

Hi masterav,

assuming that all IPs are given in decimal, the following line should do the job:

grep -wo "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" <filename>

See "man grep" for an explanation of -w and -o. The regular expression is a bit too tolerant (for example, it would also match "1000.0.0.0"), but that should not be a problem in practice.

Best regards
dmdeb

masterav 07-22-2012 10:38 AM

Thanks dmdeb
 
Dmdeb,

Simple and perfect..thats what i wanted,,,

Thanks you Dmdeb...:)


All times are GMT -5. The time now is 06:09 PM.