grep, etc
Marc Brumlik
marcbrumlik at hotmail.com
Thu Aug 19 09:06:01 PDT 2004
>> > sample data:
>> > ISA*00000089** *
>> > CLM*inv123456*a*b*c -213
>> > SV1*23456*25*A*B -214
>> >
>> > I want to be able to view a range of lines, ie: from -213 to -216
>> >
>> > In what way does this fail to meet that request?
>> > grep '-21[3-6]$' file
>>
>> Well, in the *exact* instance he used as an example, it would work.
>
>> But what happens if he wants -213 through -226?
>grep '-2[12][3-6]$' file :-)
The problem with THIS expression is it will miss everything
from -217 through -222.
Perhaps:
egrep '-21[3-9]$|-22[0-6]$' file
This could get messy for a wider range like -213 through -255.
The egrep would need three sections for the start, the end, and
everything in the middle. Like:
egrep '-21[3-9]$|-2[234][0-9]$|-25[0-5]$' file
But if you use your script to break up the user's start and end
values into hundreds, tens, and ones, you could build the three
parts of the expression and put them in variables. Then use those
variables in the egrep. The first would be the user's start value
but with the ones digit replaced with with a bracketed range
through 9. The third would be the user's end value with the ones
replaced with a bracket 0 through their value. The middle expression
catches everything in-between.
egrep "$exp1|$exp2|$exp3"
More information about the Filepro-list
mailing list