[lug] Another sed question
Bill Thoen
bthoen at gisnet.com
Sat Feb 4 07:34:37 MST 2006
On Sat, Feb 04, 2006 at 12:33:50AM -0700, Tkil wrote:
> >>>>> "Bill" == Bill Thoen <bthoen at gisnet.com> writes:
>
> Bill> Given the following items in the file called 'list':
>
> Bill> R21E
> Bill> R142E
> Bill> R12/SENW
> Bill> R222W
> Bill> R1E
>
> Bill> I want to print out only the ones where the 'R' and following
> Bill> number (which can be anything in the range of 0 to 999) is NOT
> Bill> followed by an 'E'.
>
> Although it's not clear whether you want, e.g., "R12/SENW" printed; I
> read your request as not wanting that (because it's a number from 0 to
> 999 followed by an "E", just not /immediately/ by an "E").
No, I only want the records where E does not immediately follow the number,
where the number is 1 to 3 digits long and immediately follows an 'R'.
These should be printed:
R12/SENW
R1WEEEEE
R3455E
RX12E
I'm beginning to believe that regex negation is not as straight-forward as
one might think. Or maybe it's a problem especially when preceeded by
variable expressions like [0-9][0-9]* or [0-9]\{1,3\}. For example "R1E"
will be correctly not-matched with '/R[0-9][0-9]*[^E]/' and "R25E" will be
correctly not-matched with '/R[0-9][0-9][0-9]*[^E]/' but not with
'/R[0-9][0-9]*[^E]/' as it should be. But simply turning the logic around
with '/R[0-9][0-9]*[A-DF-Z]/' works perfectly.
- Bill Thoen
More information about the LUG
mailing list