LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-06-2005, 07:22 PM   #1
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 330

Rep: Reputation: 17
grep games


I am trying to match a range of numbers with grep, and I am realising that I don't understand it as well as I thought.

$ export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'

$ for count in `seq -w 806 814`; do echo lxfshost0$count ; done

How would I grep the output : lxfshost0809 to lxfshost0812. Anything within that number range, is a positive match.

I've tried many variations of piping the output to grep and I can't match a range of numbers no matter how much experimentation I try.

Thanks.
 
Old 12-06-2005, 07:41 PM   #2
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 18
Have you tried a regular expression? I think
Code:
grep 'lxfsh0[809-812]'
would get you what you need. The single quote tells grep that it is looking at a regular expression. The lxfsh0 is text that you want it match. The real magic for you would be the [809-812] which tells it to find a the range of numbers from 809 to 812. You'll want to look up regular expressions to see what all you can do with it, and you can do a lot. Anyway, just pipe your output through that grep, and you should get what you want.
 
Old 12-06-2005, 07:53 PM   #3
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 330

Original Poster
Rep: Reputation: 17
Hello and thanks for your post.

Interesting, nope, that does'nt work if your suggesting this...

Code:
$ for count in `seq -w 806 814`; do echo lxfshost0$count ; done | grep 'lxfshost0[809-812]'
lxfshost0806
lxfshost0807
lxfshost0808
lxfshost0809
lxfshost0810
lxfshost0811
lxfshost0812
lxfshost0813
lxfshost0814

Last edited by dazdaz; 12-06-2005 at 07:55 PM.
 
Old 12-07-2005, 03:10 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
$ for count in `seq -w 806 814`; do echo lxfshost0$count ; done | grep -E'(lxfshost0809|lxfshost081[012])'
The problem you're facing is that grep knows nothing about numbers,
it compares ACSII values and sequences of those.

My regex is untested, but you get the gist ;}


Cheers,
Tink
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 01:22 PM
Games support: will my 3D games work on Linux OS? COOLER_KING Linux - Newbie 2 03-25-2004 10:50 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 02:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 04:11 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 02:34 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration