Thursday, 7 November 2013

sed script to replace one string with other. (Replacing Madras with chennai)

[singh@00-13-02-56-15-7c programs]$ vi test4.txt

Shahrukh Khan latest movie was Madras Express.
Madras is a state located in Southern part of India.
Actor Rajnikant too belong from Madras.

[singh@00-13-02-56-15-7c programs]$ vi raj10.sh


echo "enter filename with extension"
read file
sed 's/Madras/Chennai/g' $file


Output :

[singh@00-13-02-56-15-7c programs]$ sh raj10.sh
enter filename with extension
test4.txt
Shahrukh Khan latest movie was Chennai Express.
Chennai is a state located in Southern part of India.
Actor Rajnikant too belong from Chennai.



Note : 's' denotes substitute command and 'g' denotes global replacement.

No comments:

Post a Comment