How to replace line with another line in shell script
Dear All,
I have the file abc.txt cat abc.txt This is a test file Nothing is new in this world I want to replace "This is a test file" to "Text is replaced" Code Code:
FindString='This is a test file' But this is not effective. Any idea how to replace entire line either using sed or awk or any other utility. Thanks in Advance, Pramod |
Hi,
how about: Code:
sed 's/This is a test file/Text is replaced/' < abc.txt > abc.txt.new; mv abc.txt.new abc.txt |
Thanks for the reply.
The changes are not reflected when i tried to run the following command. export a="This is a test file" export b="Text is replaced" sed 's/$a/$b/' < abc.txt > abc.txt.new; mv -f abc.txt.new abc.txt |
The problem is that you have $a and $b between single quotes, meaning they will not expand to their variables.
Use double quotes if you want to expand shell variables. Eg Code:
a="This is a test file" |
It worked.. :-)
Thank you very much. |
You can also use the -i option in place replacement
Code:
bash-3.1$ cat abc.txt |
All times are GMT -5. The time now is 04:10 AM. |