Some versions of sed
require an argument for -i
. Try:
sed -i.bak 's/White/Black/' test.txt
Or (OSX/BSD only),
sed -i '' 's/White/Black/' test.txt
As you know, -i
tells sed
to edit in place. The argument the extension to use for the back-up of the original file. The argument is the empty string, your sed
will likely not keep a back-up file.
GNU sed
does not require an argument for -i
. BSD sed
(Mac OSX) does.
Details
Consider the command:
sed -i 's/White/Black/' test.txt
If your sed
requires an argument to -i
, then it would believe that s/White/Black/
was that argument. Consequently, it believes that the next argument, test.txt
, is the sed
command that it should execute. This would be interpreted as the "test" command t
with the intention of jumping to the label est.txt
if the test is true. No such label has been defined. Hence the error message:
sed: 1: "test.txt": undefined label 'est.txt'
Alternative
ThatOtherGuy reports that the following will run without error on all platforms:
sed -i -e 's/White/Black/' test.txt
ThatOtherGuy notes that the behavior of this line is, however, platform-dependent. With BSD sed
, it creates a back-up file with a -e
extension. With GNU sed
, no back-up is created.