From: Greg Russell on
"Ed Morton" <mortonspam(a)gmail.com> wrote in message
news:hai179$7gr$1(a)news.eternal-september.org...

>> I forgot the space delimiters that qualify a word:
>>
>> 's/.* has .*/has/g'
>
> Punctuation delimits words too. And then there's "has" at the start or
> end of a line...

According to what the OP has,
your point is well-taken.


From: sharma__r on
On Oct 7, 7:28 am, "Richard C. Giles" <arc...(a)gmail.com> wrote:
> On Oct 6, 8:40 pm, sharma...(a)hotmail.com wrote:
>
> > ### deleting everything before and after a word:
> > sed -e '
> >    s/has/\
> > &\
> > /
> >    s/.*\n\(.*\)\n.*/\1/
> > ' yourfile
>
> > Note: Try these on a bourne shell command line. For a c-shell -based
> > commandline the backslashes need to double.
>
> > -- Rakesh
>
> It would be a lot simpler to use:
> $ sed -e 's/.*\(has\).*/\1/' yourfile
>
> Why add tokens and additional statements when the base syntax will do
> the task.
>
>   -Arcege


The solutions I presented were to catch the first word.
The greedy regular expression you are giving will catch the last.

-- Rakesh
First  |  Prev  | 
Pages: 1 2 3
Prev: Fork Concept
Next: conditional grep-like command