[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: regexp: anything but |



lee wrote:

On Wed, Dec 09, 2009 at 06:07:34PM +0000, Chris Jackson wrote:

To match anything except |, use:

[^|]

Thanks! That's nice, but the pattern '\^.*\|[^\|]-[0-9]\|' still
matches all lines ... and I don't see why/how it could to that
... Hmm. Here's an example line:


TV|VOX-1|167(2)|136(ger),|71|12060|1089|SAstra-1H|12187|27500|h|34|-1|-1|-1|-1|-1|-1|-1|2120|||1|


<start of line> <anything> <pipe> <anything but pipe> -[-0] <pipe>
should match above line. But why does it match


TV|VOX|167(2)|136(ger),|71|12060|1089|SAstra-19.2E|12187|27500|h|34|-1|-1|-1|-1|-1|-1|-1|473|||1|


If you're in sed:

'/^[^|]*|[^|]*-[0-9]|/'

If you aren't using extended regular expressions (sed -r), pipe is not special. Also don't escape ^ ;)

Note that from the shell this is in single quote marks to stop shell expansions. Doing it without those would be masochism ;)

--
Chris Jackson


Reply to: