ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
i think i find what i look for
but i need example please
that's what i mean (sed 's/abc/(abc)/' <old >new)
so let's say the file i want edit it call /etc/file.conf
and the word i want to replace it in the /etc/file.conf " moon " i want replace moon with "sun"
sed 's/moon/sun/g' /etc/file.conf > /etc/file.conf
To be safe you might want to direct the output of sed to another file instead of /etc/file.conf. Then copy the new file in place of /etc/file.conf (probably a better idea)
sed 's/moon/sun/g' /etc/file.conf > /etc/file.conf
Ouch, that is first blanking the file.conf file, then processing it ... too late.
Quote:
To be safe you might want to direct the output of sed to another file instead of /etc/file.conf. Then copy the new file in place of /etc/file.conf (probably a better idea)
Ouch, that is first blanking the file.conf file, then processing it ... too late.
Right, so it seems, I tested and that's what it does really. Using cat to pass the file to sed helps, but I'd still go for using an alternative file for output. So:
sed 's/moon/sun/g' /etc/file.conf > /etc/file.conf.new
and then replacing file.conf with file.conf.new is the way.
if i want to clear the /etc/file.conf ? how can i do that?
i am trying something like that
############
sed -e "s/'*'/ /g" /etc/file.conf > /etc/file.conf
mv /etc/file.conf /etc/file.conf
############
and it's worked but then i got error message..
if i want to clear the /etc/file.conf ? how can i do that?
Like this:
Code:
>/etc/file.conf
Quote:
i am trying something like that
############
sed -e "s/'*'/ /g" /etc/file.conf > /etc/file.conf
mv /etc/file.conf /etc/file.conf
############
and it's worked but then i got error message..
any suggestions ?
Not sure about what do you want to achieve with this bogus code.
The first line has already been discussed.
The second one is meaningless, what is the point of moving to the same place (or renaming with the same name ...) ?
if i want to clear the /etc/file.conf ? how can i do that?
i am trying something like that
############
sed -e "s/'*'/ /g" /etc/file.conf > /etc/file.conf
mv /etc/file.conf /etc/file.conf
############
and it's worked but then i got error message..
any suggestions ?
To clear file completely just remove and re-create it:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.