Remove Text from Multiple Files

 

Shell script to remove some text from multiple files

Here is a small script that reads all *.txt  or all *.html, all *.php  files and delete all lines between word1 and word2:

#!/bin/bash
FILES="*.php"
for f in $FILES
do
INF="$f"
OUTF="$f.out.tmp"
# replace
sed '/word1/,/word2>/d' $INF > $OUTF
/bin/cp $OUTF $INF
/bin/rm -f $OUTF
done

Then save this file as “myscript.txt”

run this script with:

# bash myscript.txt