this works as I expected:
$ cat in
abc 123
$ sed -E -i .bk 's/[0-9]+/(&)/' in
$ cat in
abc (123)
$ cat in.bk
abc 123
But not this:
$ cat in
abc 123
$ sed -E 's/[0-9]+/(&)/' in
abc (123)
$ sed -E 's/[0-9]+/(&)/' in > in
$ cat in
How can I modify the above set of commands such that the last command returns, instead:
abc (123)
?
-i
option?>
, the shell will first create the file, or if it already exists, the shell will erase it's content. Whensed
tries to open the file, it is already empty. The GNU sed-i
option doesn't write to the file itself, instead sed creates a copy of the file and at the end rename that copy. If you edit a very big file you can see the copy file created.