How To Find & Replace Text within Multiple Files & Directories with Grep & Sed

Follow

 You would like to replace the following URL within ' index.html ' of all cPanel Users;

From: https://10.1.10.1:2096

To: https://foobar.com.au:2096

--

 First we have a look at ' index.html ' to see if we can make the replace more specific.

# vi /home/foouser/public_html/index.html

We find one instance that we can use ' action="https://10.1.10.1:2096 '

# grep -rl 'action="https://10.1.10.1:2096' ./ | xargs sed -i 's#action="https://10.1.10.1:2096#action="https://foobar.com.au:2096#g'

+ This will search for the string ' action="https://10.1.10.1:2096 ' in all files relative ( ./ ) to the current directory. It will then replace ' action="https://10.1.10.1:2096 ' with ' action="https://foobar.com.au:2096 ' for each occurrence of the string in every file.

Have more questions? Submit a request

Comments

Powered by Zendesk