Match exactly (and only) the pattern I specify in a grep command

Posted by palswim on Super User See other posts from Super User or by palswim
Published on 2011-01-03T20:09:13Z Indexed on 2011/01/03 20:55 UTC
Read the original article Hit count: 344

Filed under:
|
|
|

Usually, grep searches for all lines containing a match for the pattern/parameter I specify.

I would like to match just the pattern (i.e. not the whole line).

So, if a file contains the lines:

We said that we'll come.
Unfortunately, we were delayed.
Now, we're on our way.

I want to find all contractions starting with "we" (regex pattern: we\'[a-z]+/i). And I'm looking for the output:

we'll
we're

How do I do this (with grep or another Unix/Windows command-line tool)?

© Super User or respective owner

Related posts about grep

Related posts about regex