I have a large file that has a line like:
bindaddr=0.0.0.0 ; some other text
I want to replace the 0.0.0.0 with my address 192.168.1.8 and remove everything else on the line to get:
bindaddr=192.168.1.8
How can I do that?
Thanks,
jerry
Jerry Geis wrote:
I have a large file that has a line like:
bindaddr=0.0.0.0 ; some other text
I want to replace the 0.0.0.0 with my address 192.168.1.8 and remove everything else on the line to get:
bindaddr=192.168.1.8
How can I do that?
Thanks,
jerry
I finally found a way to do it with sed. Which is what I tried first but I did not have the . before the $
sed "s/bindaddr=.*/bindaddr=192.168.1.8/"
sorry to have taken tracffic.
Jerry
On Sat, Jan 24, 2009 at 10:01:56PM -0500, Jerry Geis wrote:
I have a large file that has a line like:
bindaddr=0.0.0.0 ; some other text
I want to replace the 0.0.0.0 with my address 192.168.1.8 and remove everything else on the line to get:
bindaddr=192.168.1.8
How can I do that?
given the power of unix/linux, there's probably a bazillion ways. If you want to do it from the commandline without having to use an interactive text editor, you could do it this way (note this is UNTESTED):
sed -e "s/^bindaddr=0.0.0.0.*$/bindaddr=192.168.1.8/" filename
Note the backslashes to turn the dots into literal dots, not the regexp character that it would be without the backslash. also note the single instance of a dot without a leading backslash, because that is intended to be a regexp.
OK, now it's tested. given this input file:
bindaddr=1.0.0.0 ; some other text bindaddr=2.0.0.0 ; some other text bindaddr=0.0.0.0 ; some other text bindaddr=3.0.0.0 ; some other text
applying the command above produces:
bindaddr=1.0.0.0 ; some other text bindaddr=2.0.0.0 ; some other text bindaddr=192.168.1.8 bindaddr=3.0.0.0 ; some other text
Other people would come up with something in AWK, or Perl or Ruby or PHP or <insert language du jour here>. I suppose someone with time on his hands might even figure out how to do it purely in BASH, without resorting to any external programs.
May God rest your soul if you conned me into doing your homework for you! :)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Jerry Geis wrote:
I have a large file that has a line like:
bindaddr=0.0.0.0 ; some other text
I want to replace the 0.0.0.0 with my address 192.168.1.8 and remove everything else on the line to get:
bindaddr=192.168.1.8
How can I do that?
you could try:
sed -e /bindaddr=0.0.0.0/cbindaddr=192.168.1.8 yourfile.txt | less
if it does what you want then apply the changes with adding -i:
sed -i -e /bindaddr=0.0.0.0/cbindaddr=192.168.1.8 yourfile.txt
Best Regards, - -- Alain Reguera Delgado al@ciget.cienfuegos.cu