I'm messing around with sed for fun and have a little function I found that replaces a few characters:
sed 's/"p"$/0/;s/"e"/1/' sedtext.txt
Where sedtext.txt
is as follows:
1, 2, 6, 7, "p"
1, 6, 7, 2, "e"
When I do the following I get the desired output:
sed 's/"p"$/0/;s/"e"/1/' sedtest.txt > sedtest2.txt
But when I try to overwrite the input file with the output I get a blank file:
sed 's/"p"$/0/;s/"e"/1/' sedtest.txt > sedtest.txt
Why is this the case?
sed
just prints tostdout
, which the shell pointed at a file. It reads here from the file that the shell already ate – Fox Mar 06 '17 at 16:01-i
(in-place) switch of GNUsed
does (almost) exactly your workaround – Fox Mar 06 '17 at 16:03