Search and replace multiple files with sed

Ok, if you ‘do’ Linux, then you’ll probably already know this one. I did, kind of, but had to Google to remind myself of the exact chain of commands. So here I am writing it down so it’s easier to find next time.

In my case, I had a load of Apache conf files where I needed to replace each occurrence of an IP address with an asterisk. A combo of find and sed worked well:

<code>find /etc/apache2/sites-available -type f -exec sed -i 's/*/g' {} ;</code>Code language: HTML, XML (xml)


Leave a Reply

Your email address will not be published. Required fields are marked *