help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grouping in sed with OR operator in bash in one line


From: Alan Curry
Subject: Re: grouping in sed with OR operator in bash in one line
Date: Wed, 08 Dec 2010 15:03:59 -0000

In article <caa6a54d-8488-499c-8057-f24e930f36e1@g35g2000yqa.googlegroups.com>,
Toby  <tobias.wunner@gmail.com> wrote:
>Hi,
>
>I would like to replace a a set of words by another word via sed. My
>first try was:
>
>  echo "a cat or a dog" | sed 's/\(cat\)\|\(dog\)/PET/g'
>
>I also tried some variations of this. But all failed.

Works for me:

$ echo "a cat or a dog" | sed 's/\(cat\)\|\(dog\)/PET/g'
a PET or a PET

The \(...\) aren't necessary, since the \| has low precedence.

$ echo "a cat or a dog" | sed 's/cat\|dog/PET/g'
a PET or a PET

$ sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

-- 
Alan Curry


reply via email to

[Prev in Thread] Current Thread [Next in Thread]