[svlug] extended grep reg exp

Scott Hess scott at doubleu.com
Tue Aug 12 13:37:42 PDT 2003


Break it down into pieces, something like:

egrep '^(391840[3-9]|39184[1-9][0-9]|3918[5-9][0-9][0-9]|391[9-9][0-9][0-9][0-9]|392[0-7][0-9][0-9][0-9]|3928[0-3][0-9][0-9]|39284[0-0][0-9]|392840[0-4])' myfile

Here's the set of sub-expression, to give the hang of it:

391840[3-9]
39184[1-9][0-9]
3918[5-9][0-9][0-9]
391[9-9][0-9][0-9][0-9]
392[0-7][0-9][0-9][0-9]
3928[0-3][0-9][0-9]
39284[0-0][0-9]
392840[0-4]

probably simpler would be to use Perl (or awk or something else that can 
do numeric computations):

cat myfile | perl -ne 'if (/^(\d+)\s/) { if (3918403 <= $1 && $1 <= 3928404) { print $_;}}'

Someone can probably do it shorter.

Of course, if all of the lines are sequential and fill the sequence, you 
could also do things like 'cat myfile | tail +3918403 | head -10001'.

Later,
scott


On Tue, 12 Aug 2003, Robert Khachikyan wrote:
> I've read the doc for grep extensively and google searched
> it and still couldn't find what i was looking for...on top
> of that, i left my reg exp book @ home....so here it is.
> 
> I have a big file that has
> 
> 3918400 bla bla bla
> 3918401 bla bla bla
> 3918402 bla bla bla
> 3918403 bla bla bla
> 3918404 bla bla bla
> ...
> 3945785 bla bla bla
> 3945786 bla bla bla
> 3945787 bla bla bla
> ...
> 
> you get the idea. I want to grep a portion of it out.
> Let's say from 3918403 -> 3928404 (10001 lines).
> 
> To my knowledge, grep's regular expression works with
> searching for the last character of the string(*[0-9]).
> This would return only 10 lines...what if I want to
> do a crazy grep like this?
> 
> i thought 'egrep -E 39[18403-28404] file' would do, but
> it comes back with no match...
> 
> can anyone shine a light on this....thanks a mill
> 
> 
> As Always,
> ...Robert
> 
> _______________________________________________
> svlug mailing list
> svlug at lists.svlug.org
> http://lists.svlug.org/lists/listinfo/svlug
> 





More information about the svlug mailing list