$ inline "TEXT TO REPLACE" "REPLACE WITH" filename
Make a shell script with this:
#!/bin/sh
MATCH_STRING=$1
REPLACE_WITH=$2
EDIT_FILE=$3
perl -pi.$$ -e "s{${MATCH_STRING}}{${REPLACE_WITH}}g" ${EDIT_FILE}
It will rename the files to the original filename with the current process ID on the back, and leave an edited copy in the new file.
Alternatively instead of the process ID, a timestamp (of the time now) might be more useful.
You could use:
DATE=$(date +'%Y%m%d%H%M%S')
perl -pi.${DATE} -e "s{${MATCH_STRING}}{${REPLACE_WITH}}g" ${EDIT_FILE}
or perhaps more usefully, for a timestamp based on the last modified time of the file before editing:
TIMESTAMP=$(date '+%Y%m%d%H%M%S' -r ${EDIT_FILE})
Like: 20061005151552
You might want the unix timestamp of the last modified time of the file:
TIMESTAMP=$(date +%s -r ${EDIT_FILE})
or
TIMESTAMP=$(stat -c %Y ${EDIT_FILE})
Both give: 1160057752
then:
perl -pi.${TIMESTAMP} -e "s{${MATCH_STRING}}{${REPLACE_WITH}}g" ${EDIT_FILE}
To just remove a line you can do this with the -n option:
perl -ni.$$ -e "print if !~ /^${MATCH_STRING}:/;" ${EDIT_FILE}
But this is shorter:
perl -pi.$$ -e "s/^${MATCH_STRING}:.*?\n//g;" ${EDIT_FILE}