So I want to create a script that takes 3 arguments - path to file, exact word to replace and with what to replace it. How to create such thing?
Generally I want6 it to have api like sudo script.sh "C:/myTextDoc.xml" "_WORD_TO_REPLACE_" "WordTo Use"
Something like this?
Alternatively, you can use the single command
as Yan suggested. I generally use the first form myself. I have seen systems where
-i
is not supported (SunOS).This will replace all instances of the second argument with the third, in the file passed as the first. For example,
./replace file oldword newword
You don't need a script, a simple sed would do (if you're running under cygwin or a POSIX-compliant OS):
Ruby(1.9+)