Shell Script To Replace String in A File -1
Shell Script To Replace String in A File
using linux sed command we can find a word or string in a file and we can replace a that string with another new string.
Shell Script To Replace String in A File
sed -i -e 's/old/new/g' hello.txt sed -i -e 's/cat/dog/g' hello.txt or sed -ie 's/cat/dog/g' hello.txt
above command will find all strings called as a cat and it will replace all cat strings with dog.
s/
is used to substitute the found string cat with dog
/g
stands for "global". i.e. replace all and not just the first occurrence
-i
option is used to edit in place on the file hello.txt
.
-e
option indicates the expression/command to run, in this case s/
.
- shell script to replace a string in a file
- shell script to replace text in file