Re: regular expression question
- From: Orson <moleskyca1@xxxxxxxxx>
- Date: Thu, 15 May 2008 13:33:10 -0700 (PDT)
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.
.
- References:
- regular expression question
- From: Orson
- Re: regular expression question
- From: Jim Gibson
- regular expression question
- Prev by Date: Need ideas on how to make this code faster than a speeding turtle
- Next by Date: Re: Need ideas on how to make this code faster than a speeding turtle
- Previous by thread: Re: regular expression question
- Next by thread: Re: regular expression question
- Index(es):
Relevant Pages
|