4

When I am running sed operations on a file, for example:

sed 's/this/that/' /my/file.txt

The output is displayed on stdout.

However, when I apply the changes in place with -i there is no stdout (no output at all to screen).

sed -i 's/this/that/' /my/file.txt

How can I still output to screen when I'm using the -i trigger?

1 Answer 1

3

You can't. You've probably already noticed that if you

sed -i 's/this/that/p' /my/file.txt

it just includes that line twice in /my/file.txt.

You can, of course, cheat:

sed -i 's/this/that/' /my/file.txt; cat /my/file.txt

or, if appropriate

sed -i 's/this/that/' /my/file.txt && cat /my.file.txt

You must log in to answer this question.

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