1

Whenever i am using my sed command in ubuntu the output is not reflected in the file.

sed 's/dog/cat/' me

does not change dog hates rat in the file to cat hates rat in the file me.

1

1 Answer 1

3

By default, sed does not edit the input file, it just shows the output on STDOUT.

To edit a file in place, you need the -i option of sed:

sed -i.bak 's/dog/cat/' file.txt

After the operation, the original file will be backup up as file.txt.bak and the modified file will be file.txt.

In your case:

sed -i.bak 's/dog/cat/' me

If you do not want to keep a back up:

sed -i 's/dog/cat/' file.txt

From man sed:

-i[SUFFIX], --in-place[=SUFFIX]

edit files in place (makes backup if SUFFIX supplied)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .