sed command is not working on windows 10
10,260
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
Comments
-
VijayVishnu almost 2 years
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
-
Sundeep over 7 yearswhat is the output of
sed --version
? -
VijayVishnu over 7 years@spasic GNU sed version 3.02
-
Sundeep over 7 yearsI think that version doesn't have inplace editing option.. you can try a workaround:
sed 's/how/where/' new.txt > tmp.txt && mv tmp.txt new.txt
or useperl
if it is available -
VijayVishnu over 7 yearswhere to get the latest sed?@spasic
-
VijayVishnu over 7 yearsunxutils.sourceforge.net this was having latest version 3.02 only
-
Sundeep over 7 yearsno idea, this might help: unix.stackexchange.com/questions/111673/… and stackoverflow.com/questions/7232797/…
-
Tim over 7 yearsI downloaded UnxUpdates.zip from unxutils.sourceforge.net and it contained
GNU sed version 4.0.7
, which supports the-i
option. Can you make sure you have the latest version installed?
-