Results 1 to 5 of 5
Hi all,
I want to edit a .conf file on the fly, so I have decided to use sed.
The line in focus looks like this
Code:
server 127.127.25.0 minpoll ...
- 05-14-2007 #1Just Joined!
- Join Date
- Sep 2006
- Posts
- 22
Issue with sed
Hi all,
I want to edit a .conf file on the fly, so I have decided to use sed.
The line in focus looks like this
in which I have to replace last 1 with 7 Henceforth sed may be used asCode:server 127.127.25.0 minpoll 1
which meansCode:sed -ie 's/^server\(*\)[[:digit:]]/\17/'
i) search for a line starting with "server"
ii) target the last digit
iii) replace the target with 7
for which I'm expecting an output like
but what I get isCode:server 127.127.25.0 minpoll 7
can someone help me in this issueCode:127.127.25.0 minpoll 7
- 05-14-2007 #2
You need to put some escaped brackets around server and then output \1\2 before the number 7 (or you could just rewrite server in the replacement field). \1 only refers to what is inside the first set of escaped brackets so does not include server. This is what works on mine:
RegardsCode:sed -ie "s/^\(server\)\(.*\)[0-9]/\1\27/" test.conf
- 05-14-2007 #3Just Joined!
- Join Date
- Sep 2006
- Posts
- 22
Thanks Birdman
It does work. Is there any system call that can replace this sed, instead calling sed from system().
- 05-14-2007 #4Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:awk '/^server/{$NF=7}1'
- 05-14-2007 #5
What language are you writing in?
I don't know of any that model sed to allow you to do it as elegantly but post back and someone might be able to help.


Reply With Quote