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

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 01-25-2009, 02:01 AM
Jerry Geis
 
Default replacing a line in a file

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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-25-2009, 02:17 AM
Jerry Geis
 
Default replacing a line in a file

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
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-25-2009, 02:21 AM
fred smith
 
Default replacing a line in a file

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!


--
-------------------------------------------------------------------------------
Under no circumstances will I ever purchase anything offered to me as
the result of an unsolicited e-mail message. Nor will I forward chain
letters, petitions, mass mailings, or virus warnings to large numbers
of others. This is my contribution to the survival of the online
community.
--Roger Ebert, December, 1996
----------------------------- The Boulder Pledge -----------------------------
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 01-25-2009, 02:21 AM
Alain Reguera Delgado
 
Default replacing a line in a file

-----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>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with CentOS - http://enigmail.mozdev.org

iD8DBQFJe9rXyXxCQEoXDZARAj5uAJ9ZYDXe443zZZivi1JRzm fnrMAH6wCgr0C0
pIJ9Wbb5ZNhHcjPMK7QO8cY=
=Lv+e
-----END PGP SIGNATURE-----
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




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

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