VijayVishnu
VijayVishnu

Reputation: 537

sed command is not working on windows 10

I tried to run the below command in my windows 10 machine. Here, new text file contains some text like this 'how are you?'. I want to replace the string 'how'->'where' in that same file without creating a new file. But It shows error. Any comments to resolve it?

sed -i s/how/where/ new.txt

sed: invalid option -- i

enter image description here

Upvotes: 2

Views: 14389

Answers (1)

Tim
Tim

Reputation: 4958

Your version of sed (GNU sed version 3.02), does not support the -i option. You can either update to a more recent version of sed (version 4.2.1 is available here), or work around the issue by redirecting to a temporary file and then copying it to the source file:

C:\>cat.exe foo.txt
foo
how
bar
baz
foo how bar

C:\>sed.exe s/how/where/ foo.txt > foo2.txt

C:\>move /Y foo2.txt foo.txt
        1 file(s) moved.

C:\>cat.exe foo.txt
foo
where
bar
baz
foo where bar

Upvotes: 1

Related Questions