FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 02-12-2008, 10:09 PM
"Scott Ruckh"
 
Default SED help

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="(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[ ]${IP_REGEX}[ ]${IP_REGEX}[ ]${IP_REGEX}[
]${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.

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 02-12-2008, 10:22 PM
"Scott Ruckh"
 
Default SED help

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="(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[ ]${IP_REGEX}[ ]${IP_REGEX}[ ]${IP_REGEX}[
]${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.

--
My editor cut off some of the text, I assume due to line being too long.
Hopefully it is clear what I am trying to accomplish with the incomplete
information above


Thanks.


--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 02-12-2008, 10:34 PM
"Herta Van den Eynde"
 
Default SED help

On 13/02/2008, Scott Ruckh <sruckh@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="(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[ ]${IP_REGEX}[ ]${IP_REGEX}[ ]${IP_REGEX}[
> ]${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."

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 02-13-2008, 12:30 AM
"Scott Ruckh"
 
Default SED help

This is what you said Herta Van den Eynde
> On 13/02/2008, Scott Ruckh <sruckh@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="(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[ ]${IP_REGEX}[ ]${IP_REGEX}[ ]${IP_REGEX}[
>> ]${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
>
Here is the poorly coded version I ended up with...

This is going to be used to dynamically update my openvpn configuration
server configuration.

#!/bin/sh

OUTFILE=/etc/openvpn/eth.txt
SED=`which sed`
PERL=`which perl`
OVPN_CFG=/etc/openvpn/mytest.txt

eth_ip=`/sbin/ifconfig | /bin/grep 'inet addr:'| /bin/grep -v '127.0.0.1'
| /usr/bin/cut -d: -f2 | /usr/bin/awk '{print $1}'`

echo $eth_ip > $OUTFILE

oct1=`/usr/bin/cut -d. -f1 $OUTFILE`
oct2=`/usr/bin/cut -d. -f2 $OUTFILE`
oct3=`/usr/bin/cut -d. -f3 $OUTFILE`
CLASS_C="${oct1}.${oct2}.${oct3}"

rm -f $OUTFILE

BRIDGE_STRING="server-bridge ${eth_ip} 255.255.255.0 ${CLASS_C}.30
${CLASS_C}.35"
IP_REGEX="d{1,3}.d{1,3}.d{1,3}.d{1,3}"
BRIDGE_REGEX="server-bridge[ ]${IP_REGEX}[ ]${IP_REGEX}[
]${IP_REGEX}[ ]${IP_REGEX}"

${PERL} -pi -e "s/${BRIDGE_REGEX}/${BRIDGE_STRING}/g" $OVPN_CFG

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 02-13-2008, 12:50 AM
mark
 
Default SED help

Scott Ruckh 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 believe, given what you say above, that you'd get
some-text 1111 1111 1111 1111

mark

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 03-09-2010, 03:56 PM
chloe K
 
Default sed help

Hi

Can I know how to use sed to substitue 2 instead of 1 at the same time?

eg:

sed 's/pchloe.com/abc.com/ ; /192.92.123.5/10.10.0.3/g' orgfile >> newfile

thank you


__________________________________________________ ________________
Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-09-2010, 04:08 PM
Paul Heinlein
 
Default sed help

On Tue, 9 Mar 2010, chloe K wrote:

> Hi
>
> Can I know how to use sed to substitue 2 instead of 1 at the same time?
>
> eg:
>
> sed 's/pchloe.com/abc.com/ ; /192.92.123.5/10.10.0.3/g' orgfile >> newfile

sed
-e 's/pchloe.com/abc.com/g'
-e 's/192.92.123.5/10.10.0.3/g'
orgfile >> newfile

--
Paul Heinlein <> heinlein@madboa.com <> http://www.madboa.com/
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 03-09-2010, 04:13 PM
Dan Burkland
 
Default sed help

> -----Original Message-----
> From: centos-bounces@centos.org [mailto:centos-bounces@centos.org] On
> Behalf Of Paul Heinlein
> Sent: Tuesday, March 09, 2010 11:08 AM
> To: CentOS mailing list
> Subject: Re: [CentOS] sed help
>
> On Tue, 9 Mar 2010, chloe K wrote:
>
> > Hi
> >
> > Can I know how to use sed to substitue 2 instead of 1 at the same time?
> >
> > eg:
> >
> > sed 's/pchloe.com/abc.com/ ; /192.92.123.5/10.10.0.3/g' orgfile >>
> newfile
>
> sed
> -e 's/pchloe.com/abc.com/g'
> -e 's/192.92.123.5/10.10.0.3/g'
> orgfile >> newfile
>
> --
> Paul Heinlein <> heinlein@madboa.com <> http://www.madboa.com/
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos

You can also use semi colons for example:

sed 's/pchloe.com/abc.com/; s/192.92.123.5/10.10.0.3/g' orgfile >> newfile

Dan
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 07:39 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org