Archive

Posts Tagged ‘text’

Remove Text from Multiple Files

February 18th, 2010 Comments off

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

Categories: Linux Tags: , , , , , , , ,