SED help

Herta Van den Eynde herta.vandeneynde at gmail.com
Tue Feb 12 23:34:10 UTC 2008


On 13/02/2008, Scott Ruckh <sruckh at gemneye.org> wrote:
> I would like to do the following SED replacement, but I am not having much
> luck and thought I would ask for help.
>
> TEXT1="some-text a.b.c.d a.b.c.d a.b.c.d a.b.c.d"
> TEXT2="some-text 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4"
>
> sed -i "s/$TEXT1/$TEXT2/g" $INFILE
>
> ;a.b.c.d are unknown IP Addresses.
>
> ----------------------
>
> I have tried this:
>
> TEXT2="some-text 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4"
> IP_REGEX="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][$
> TEXT1="^some-text[ \t]${IP_REGEX}[ \t]${IP_REGEX}[ \t]${IP_REGEX}[
> \t]${IP_REGEX}"
>
> sed -i "s/$TEXT1/$TEXT2/g" $INFILE
>
> ----------------------
>
> What I have does not work, and I need some assistance.
>
> Your help is appreciated.
>
> Thanks.
>
I think you simply missed out on the option: -e instead of -i.  This
works for me:

TEXT1="some-text a.b.c.d a.b.c.d a.b.c.d a.b.c.d"
TEXT2="some-text 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4"

sed -e "s/$TEXT1/$TEXT2/g" $INFILE

Kind regards,

Herta
-- 
"Life on Earth may be expensive,
 but it comes with a free ride around the Sun."




More information about the redhat-list mailing list