From: JF Mezei on
Sorry for the newbie question:

what is the grep syntax to look for the string "velo" but NOT
"development" ?
From: David Empson on
JF Mezei <jfmezei.spamnot(a)vaxination.ca> wrote:

> Sorry for the newbie question:
>
> what is the grep syntax to look for the string "velo" but NOT
> "development" ?

You can't really do that with a simple grep.

The closest you could get would be to search for lines containing "velo"
where the character before or after it didn't match the corresponding
character in "development"

For example:

velo[^p]

will find all lines containing the characters "velo" where the next
character is not a 'p'.

The catch is that there has to be a next character. If the line ends
with "velo" then it will fail to match.

A better solution is to use grep twice, piping the result of one to the
next and excluding the lines you don't want. For example

grep velo *.txt | grep -v develop

The -v option reverses the test, so the second grep will print all lines
output by the first grep which don't contain "develop". Of course, if
the filenames include the word "develop" then you have a more complex
problem to solve.

This might work:

grep velo *.txt | grep -v "^[^:]+:.*develop"

The regular expression means "start of line, then one or more non-colon
characters, then a colon, then anything, then "develop"; the -v will
exclude any lines which match that pattern.

The first grep will be outputting text like:

filename1:velo
filename2:velocity
filename3:develop
mydevelop:velo

The second grep will exclude filename3 but retain mydevelop.

--
David Empson
dempson(a)actrix.gen.nz
From: Warren Oates on
In article <00d3fbcf$0$26906$c3e8da3(a)news.astraweb.com>,
JF Mezei <jfmezei.spamnot(a)vaxination.ca> wrote:

> Sorry for the newbie question:
>
> what is the grep syntax to look for the string "velo" but NOT
> "development" ?

grep ^velo
--
Very old woody beets will never cook tender.
-- Fannie Farmer
From: TF on
On Thu Jan 21 2010 at 10:30:39 UTC, JF Mezei <jfmezei.spamnot(a)vaxination.ca> wrote:
> Sorry for the newbie question:
>
> what is the grep syntax to look for the string "velo" but NOT
> "development" ?

You can do that "properly" with regular expressions but, at least in
simple cases, I find myself piping multiple instances of grep instead,
e.g.

cat file.txt | grep "velo" | grep -v "development"

Here, "-v" makes grep perform what's called an "inverted matching", that
is, it passes everything through that does NOT match "development".

Tom
From: Barry Margolin on
In article <00008637$0$2265$c3e8da3(a)news.astraweb.com>,
Warren Oates <warren.oates(a)gmail.com> wrote:

> In article <00d3fbcf$0$26906$c3e8da3(a)news.astraweb.com>,
> JF Mezei <jfmezei.spamnot(a)vaxination.ca> wrote:
>
> > Sorry for the newbie question:
> >
> > what is the grep syntax to look for the string "velo" but NOT
> > "development" ?
>
> grep ^velo

That looks for lines BEGINNING with "velo". He never said that.

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***