Re: regular expression question



On May 15, 3:12 pm, Jim Gibson <jimsgib...@xxxxxxxxx> wrote:
In article
<1abd8794-b762-400e-9079-4876c603e...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,

Orson <molesky...@xxxxxxxxx> wrote:
Sorry, this is probably silly question, but I cannot find right
answer.

I am trying to use grep -P (for perl regular expressions). I want to
match lines that do not contain the chars "sync".

Does your grep have the '-v' switch ('--invert-match'):

  grep -v sync



I thought I could do:

grep -P "[^(sync)]" mytextfile

I understand [] matches any char in the brackets and (sync) groups
those chars together, so I would negate to mean should not match those
chars.

Parentheses group, but not inside brackets. "[^(sync)]" will match any
character other than the 6 listed. In Perl, you would negate the test:

  $string !~ /sync/;

but that won't work as an option for grep. My grep doesn't have a '-P'
switch, so I can't tell how to use it. However, the -v switch seems to
do what you want.

--
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
               http://www.usenet.com

Yes, this is interesting and it works. I was trying to get the same
you get in perl when you do $string !~ /sync/ as you mentioned. I have
a solution to problem and I thank you for that. Out of curiosity how
would you negate a word with regex with grep if you didn't have the -v
option or anything like it ? I am not sure I know because my way as
just matching characters, but you want to say lines that do NOT have
the word "sync". Perhaps there is no way using regex.
.



Relevant Pages

  • Re: [SLE] grep
    ... > Wonder if someone could give me the way to grep for an word within all ... > files on my system like the filename would be XXXX.XX ... will do a case insensitive file match for all files with 4 chars ...
    (SuSE)
  • Re: regular expression question
    ... I am trying to use grep -P (for perl regular expressions). ... match lines that do not contain the chars "sync". ... switch, so I can't tell how to use it. ...
    (comp.lang.perl.misc)
  • Re: transliterate the negative character class in perl
    ... RC> How does one transliterate in perl using a negated character class? ... will see how to negate its list of chars and that using is not only ...
    (perl.beginners)
  • Re: findstr doesnt always find
    ... properly handled search strings longer than 115+ chars. ... so I'll see how its grep holds up. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: regex, negations, grep, find and replace (a few questions)
    ... A problem is that grep works line by line. ... Is there anything like grep that does not have this problem/feature? ... characters before piping the text to grep, ... I heard that it is hard to negate a regex. ...
    (alt.os.linux)