LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-22-2012, 10:23 AM   #1
masterav
Member
 
Registered: Aug 2008
Location: India
Distribution: redhat el5,fedora,centos
Posts: 30

Rep: Reputation: 0
Question 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..
 
Old 07-22-2012, 10:32 AM   #2
dmdeb
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian
Posts: 45

Rep: Reputation: 6
Quote:
Originally Posted by masterav View Post
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
 
Old 07-22-2012, 10:38 AM   #3
masterav
Member
 
Registered: Aug 2008
Location: India
Distribution: redhat el5,fedora,centos
Posts: 30

Original Poster
Rep: Reputation: 0
Thumbs up Thanks dmdeb

Dmdeb,

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

Thanks you Dmdeb...
 
  


Reply

Tags
awk, grep, sed, wildcard


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] C++ : function adress/ Variable adress LoDam Programming 1 03-29-2011 05:41 AM
[SOLVED] Using grep with wildcards SimianDysfunction Linux - Newbie 5 07-04-2010 06:55 AM
need help with wildcards yanivmomo Programming 4 05-24-2010 07:37 AM
Use of wildcards and -R switch in ls and grep robgee1964 Linux - Newbie 7 12-04-2005 05:20 PM


All times are GMT -5. The time now is 04:40 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration