You are not logged in.
Pages: 1
How can 'sed' (or any other line editor) be used to insert text,
like add 'hal' and 'fam' in DAEMONS in /etc/rc.conf
or adding something to MODULES line?
i couldn't make out the meaning in 'man sed', hence looking for reverse way, ie, asking u to kindly give a short one line example.
Offline
MODULES=(fam hal) ?
Every day I make furniture:) Polecam meble na wymiar meble poznań & kuchnie na wymiar poznań.
Offline
sed -i '/^DAEMONS=/ s/)$/ fam)/' rc.conf
Adds fam at the end of DAEMONS.
You should have a look at http://www.grymoire.com/Unix/Sed.html (or other tutorials for sed and regular expressions)
Last edited by byte (2009-03-27 14:21:35)
1000
Offline
is there a reason you are wanting to use sed instead of editing the file by hand?
Offline
is there a reason you are wanting to use sed instead of editing the file by hand?
I'm gonna have to pose the same question...SED can be very unforgiving...as I've found out the hard way
furthermore...I typically use SED for more of a "search and replace" strategy than simply adding to the end of a file. For example...replacing "line that starts and reads like this" to something like "line that used to start one way, but now reads like this".
If youre simply appending data to the end of a file....cat may be a better option for you.
This way you could add "line that used to start one way, but now reads like this" directly to the end of the file using a command something like:
cat original >> new
even better for testing purposes would be:
cat original text_to_add > new.txt
this way would take the original file, plus the file with the text you wish to add, and create a whole new file called new.txt. then you could verify its what you want and simply move / rename it as appropriate.
for that - ill hae to advise checking out the cat command moreso than sed.
nonetheless I may be missing the mark totally on what youre trying to accomplish...but in the end I think editing it by hand is the safest / easiest / smartest way to do things.
If youre looking to learn sed it would be much wiser to practice on dummy files
good luck!
Offline
Thanks indeed for your replies.
why i wanted it with sed? ---> to kill Bug no. 509 in my frontal lobe that urged me do do it via command line ; to make a small script that accomplishes a few small installation editings.
Offline
Next time, search Google or check the man page.
Last edited by haxit (2009-03-28 16:27:59)
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Next time, search Google or check the man page.
A bit harsh, isn't it?
But, true, try to understand how to help yourself. info sed is a good source of documentation. Also, there are quite some outstanding sed tutorials available in the web.
This applies to similar problems as well of course.
If you try for yourself you will always find a helpful hand once you got stuck.
Last edited by bernarcher (2009-03-28 21:11:25)
To know or not to know ...
... the questions remain forever.
Offline
haxit wrote:Next time, search Google or check the man page.
A bit harsh, isn't it?
But, true, try to understand how to help yourself. info sed is a good source of documentation. Also, there are quite some outstanding sed tutorials available in the web.This applies to similar problems as well of course.
If you try for yourself you will always find a helpful hand once you got stuck.
I didn't mean it in a harsh way, it was a friendly suggestion. Maybe I should have put a or or or or after it.
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Pages: 1