inside the mind of a linux admin

search and replace

Example: Customer has been a victim of iframe code injections in multiple pages. Use this grep/sed command will come in handy for clearing the majority of them out. Please be careful and test first with just the grep command to ensure you don’t clear out anything you need.
Does NOT backup files, be sure to backup first!


this will remove all iframe injections from a particular file or wildcard set of files

usage example: ./ *.php

Example: Replacing /var/named domains IP addresses with perl

Sometimes you need to replace an instance of one string in a file with another string. If there’s multiple occurrences, this can be a pain. Here’s a simple example of how you can use perl to replace all instances of an IP address for a moved a domain.

To do it:

perl -i.bak -pe “s/” /var/named/

This example shows how to change from IP to
This will also makes a backup of /var/named/ as /var/named/

If you’re feeling ballsy and do not want backup run:

perl -i -pe “s/” /var/named/

One alternate way would be (without perl):

replace — /var/named/

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.