sed - quick help?

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
hey guys,

I have a cfg file that needs updating a but I'm being lazy and want to script it.

I have a little Linux experience but I'm new to both sed and awk.
this is what I have so far (after spending some time on google and sed's man pages) but it's not adding the new string...

Code:
sed '/string to find in file/ a\
new line and string to insert' mycfgfile

Any ideas what I'm doing wrong?

Thanks in advance :)
 
Not sure I follow ... but if its a simple find replace:

If you have a test file (test.txt) with text
oveeeer clocker test

then:
Code:
sed -i 's/oveeeer clocker/overclocker/g' test.txt

will yield

overclocker test

edit: Adding New line


then:
Code:
sed -i 's/oveeeer clocker/overclocker\nrules/g' test.txt

will yield

overclocker
rules test
 
Last edited:
cheers guys.

I got it working with;

cat org_file | sed '/string to search for/ a\
string to insert' > new_file


now, Ideally, I'd like to change the 'string to insert' to be a variable.

any ideas on how I can do this as simply putting in $foo only prints '$foo' into the file, not the value it contains
 
Back
Top Bottom