How to search and replace
Dan Track
dan.track at gmail.com
Thu Feb 2 15:50:07 UTC 2006
On 2/2/06, Paul Howarth <paul at city-fan.org> wrote:
> Dan Track wrote:
> > Hi
> >
> > I thought I'd ask this here as you guys helped me setup mrtg :)
> >
> > I've got the following pattern in a text file in linux.
> > Target[description1].1.3.4.6.5.3.:string at 10.11.8.10
> > Directory[description1]: server1
> >
> > Target[description2].1.3.4.6.4.9.:string at 10.17.5.24
> > Directory[description2]: server2
> >
> > What I would like to do is replace the ip of each with the following
> > value of "Directory". So for example I would like
> > Target[description1].1.3.4.6.5.3.:string at 10.11.8.10 to become
> > Target[description1].1.3.4.6.5.3.:string at server1.example.com
> >
> > How can I accomplish this using either C,perl,sed or awk
>
> sed -e '$b
> /^Target\[[^]]*\][.0-9]*:.*@[0-9.]*$/ {
> $!N
> s/^\(Target\[[^]]*\][.0-9]*:.*@\)[0-9.]*\nDirectory\[[^]]*\]:
> \(.*\)$/\1\2.example.com/
> P;D
> }' textfile > output
>
Thanks for the reply. When I run it I get the following error:
sed -e '$b /^Target\[[^]]*\][.0-9]*:.*@[0-9.]*$/ {
> $!N
> s/^\(Target\[[^]]*\][.0-9]*:.*@\)[0-9.]*\nDirectory\[[^]]*\]:
> \(.*\)$/\1\2.example.com/
> P;D
> }' text_files/mrtg.cfg > text_files/mrtg.cfg.changed
sed: -e expression #1, char 108: unterminated `s' command
Any ideas?
Thanks
Dan
More information about the fedora-list
mailing list