The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sed Range Issue Wrathe Shell Programming and Scripting 2 06-17-2008 03:54 PM
Copying specific files from remote m/c to specific folders jhoomsharabi Shell Programming and Scripting 0 06-12-2008 07:31 AM
specifing range.... zedex UNIX for Advanced & Expert Users 1 10-19-2007 09:07 AM
Look a string within a range! azmathshaikh Shell Programming and Scripting 0 05-01-2005 03:54 AM
Unix SCO 5.0.6 Out of range josramon UNIX for Dummies Questions & Answers 5 02-21-2003 02:06 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 07-16-2008
sylaan sylaan is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 14
Match a specific IP range

Hello all,

I would like a bit of help with a problem I am having. I have the following example file:

$ cat test_hosts
10.10.2.3 host1
10.10.2.4 host2
10.10.2.130 host3
10.10.2.5 host4
10.10.2.230 host5
10.10.2.22 host6

I need to match all IP addresses in the 10.10.2.1-10.10.2.22 range. I have tried all kind of things but for the life of me, I can't get it to work.

$ cat test_hosts | egrep "10\.10\.2\.[1,22]\s"

This shows nothing.

$ cat test_hosts | egrep "10\.10\.2\.[1,22]"
10.10.2.130 host3
10.10.2.230 host5
10.10.2.22 host6

Not exactly what I need. What am I doing wrong ?


Thanks,
Sylaan
  #2 (permalink)  
Old 07-16-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
Code:
sort -t "." -k 1,1n -k 2,2n -k 3,3n -k 4,4n infile| sed -n '/10.10.2.3 /,/10.10.2.22/p'
Sorry, that's not good as you have to specify an existing start and end, ie. .3 and .22. I have no better idea atm, but I bet someone will come up with a better code soon.

Your code doesn't work because [1,22] is not a range in regular expressions. Afaik it would be written [1-22] but I don't get it working either
  #3 (permalink)  
Old 07-16-2008
sylaan sylaan is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 14
Yeah, forgot to mention that I tried the [1-22] and it didn't work for me either. I am on a SunOS 5.10.

The sort command works, thanks for that. Unfortunately I will have to eventually parse very large syslog files and I imagine that's not so efficient and fast
  #4 (permalink)  
Old 07-16-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,860
Something like this:

Code:
egrep '10\.10\.2\.([1-9]|(1[0-9]|2[0-2])) ' test_hosts
  #5 (permalink)  
Old 07-16-2008
sylaan sylaan is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 14
That works, much thanks
  #6 (permalink)  
Old 07-16-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
Yep, good to know, ty radoulov!
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0