Re: Need to grep between a range (185 Views)
Reply
Super Advisor
Allanm
Posts: 287
Registered: ‎08-13-2007
Message 1 of 4 (185 Views)
Accepted Solution

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
Please use plain text.
Honored Contributor
VK2COT
Posts: 921
Registered: ‎01-17-2006
Message 2 of 4 (185 Views)

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
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,585
Registered: ‎05-19-2003
Message 3 of 4 (185 Views)

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.






Please use plain text.
Super Advisor
Allanm
Posts: 287
Registered: ‎08-13-2007
Message 4 of 4 (185 Views)

Re: Need to grep between a range

Thanks Folks
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation