View Full Version : Can Someone explain how to use Sed?

14th April 2007, 09:09 PM
Topic mostly has the question covered. I was wondering how the sed command can be used to change a line of a file. I was trying to use the sed command to modify a line of code in /etc/sysconfig/network-scripts/ifcfg-eth1 from RATE='0 kbs' to RATE=Auto but i kept getting errors.

I think it would be something along the lines of sed 's/RATE='0 kbs'/RATE=Auto' /etc/sysconfig/network-scripts/ifcfg-eth1 but I am not certain. Could someone explain what the s does and how the single quotes work. Do the single quotes in the part I want to replace affect it?

14th April 2007, 11:50 PM
Check your quotes, you trying to enclose single-quotes in single-quotes, which doesn't work. Either use double quotes or escape the inside quotes.

15th April 2007, 12:16 AM
I tried double quotes and that didnt seem to work. By escape the inside quotes do you mean to put a forward slash before the single quotes inside the other single quotes?

15th April 2007, 01:15 AM
Backwards slash, but I don't see any reason double quotes wouldn't work. "kept getting errors" is pretty useless, try posting the actual error messages and you may get better answers.

15th April 2007, 05:58 AM

I explained how to do this in a previous post of yours about C programming. Take a look at what I posted there. look CLOSELY at how I formatted it.