modifying file using script

Hi,

I am new to shell programming, and want to know is it possible to change the contents of file using script?

for example, if want to search 2 words and want to replace these words with 2 new words.

Regards,

Manoj

Yes, it is posssible

Eg

file.txt
aaa
bbb
ccc

Now if i want to replace bbb with ddd ,use

sed 's/bbb/ddd/' file.txt > file1.txt

Note you can't directly modify a file, you have to redirect it to other file

Note you can't directly modify a file, you have to redirect it to other file

You can using perl one liner.

you can... but not with "sed" which is the "stream editor". but you can use "ed" to alter a file directly. afaik it uses the same syntax as "sed"!

You can edit a file inplace with sed, without redirection with the '-i' switch if you have it...

sed -i~ 's/bbb/ddd/' 'file'

-Enjoy
fh : )_~