The basic command for replacing occurences of a particular string in a file to another string and output to a new file:
Let’s call our source file file1
sed 's/'old string'/'new string'/' file1 Example sed 's,'CONFIG_TUN=m','#CONFIG_TUN=m','lconfig
This will output the replaced text to screen. If you want to make changes in the file, you need to pipe it to a new file and finally move the file back to original name.
sed 's/'old string'/'new string'/' file1 > file2 ; mv file2 file1[/code] And to test if it was successful:grep -i 'new string' destinationfile
Joel G Mathew, known in tech circles by the pseudonym Droidzone, is an opensource and programming enthusiast.
His favorite pastime is grappling with GNU compilers, discovering newer Linux secrets, writing scripts, hacking roms, and programs (nothing illegal), reading, blogging. and testing out the latest gadgets.
When away from the tech world, Dr Joel G. Mathew is a practising ENT Surgeon, busy with surgeries and clinical practise.