Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Need to grep between a range

SOLVED
Go to Solution
Super Advisor

Need to grep between a range


I have following output from a wget command -

1238029403|tobc10|99
1238029403|tobc11|725
1238029403|tobc12|734
1238029403|tobc13|99
1238029403|tobc14|99
1238029403|tobc15|99
1238029403|tobc16|99
1238029403|tobc17|99
1238029403|tobc18|100
1238029403|tobc19|100
1238029403|tobc20|146
1238029403|tobc21|99
1238029403|tobc24|619
1238029403|tobc2|670
1238029403|tobc3|720
1238029403|tobc4|389
1238029403|tobc5|768
1238029403|tobc6|99
1238029403|tobc7|720
1238029403|tobc8|738
1238029403|tobc9|718
1238029403|tob|1384

And I need to grep for rows in which the value is less than 100.

Here is what I have been trying but doesnt work -
cat tmp|egrep 'tob [0-99]'


Please Help!

Thanks,
Allan
3 REPLIES
Honored Contributor [Founder]

Re: Need to grep between a range

I assume you are talking about the third
column?

If so, here is one of the solutions:

awk -F"|" '$3 <= 99 {print}' tmp

I just tested it on my Fedora 10 server. Works fine. I am not at my desk at the moment so
I cannot check it on an HP-UX server.

Cheers,

VK2COT
VK2COT - Dusan Baljevic
Honored Contributor [Founder]

Re: Need to grep between a range

Hmm, why 'cat' before 'grep'?
Grep will happily read a file on it's own.

With 'the value', do you mean the last column when treating a bar as a column seperator? Then what is the 'tob' doing in the search string?


In that case any value less than 100 which has 1 or 2 digits only, will have a | seperator 2 or 3 bytes from the end of line.

So try:

grep -e "|..$" -e "|.$" tmp

The expression [0-99] you presented translates to: a single character in the range 0 thru 9, or 9.


You MIGHT want:

grep -e "|[0-9][0-9]$" -e "|[0-9]$" tmp

Hope this helps,
Hein.






Highlighted
Super Advisor

Re: Need to grep between a range

Thanks Folks