GTKC Knowledgebase
A little bit of wisdom
Removing lines of text with SED
Posted by  Admin on


This will remove a specific block of text between two pointers.

sed '/<script type="text\/javascript"/,/<\/script>/d' <filename>

..will remove all text between /<script...> and <\/script> (Including the <\/script> tags.

Here is a short shell script to automate this for a bunch of files.

#!/bin/bash
# ALL HTML FILES
FILES="*.html"
# for loop read each file
for f in $FILES
do
INF="$f"
OUTF="$f.out.tmp"
# replace javascript
sed '/<script type="text\/javascript"/,/<\/script>/d' $INF > $OUTF
/bin/cp $OUTF $INF
/bin/rm -f $OUTF

Tags: Text manipulation , Linux
Return to home page: Home