≡ Menu

sed delete lines between words

Linux / Unix sed: Delete Word From File / Input

I‘ve a file as follows:

This is a test.
One bang two three
Foo dang Bar
001 0xfg 0xA
002 0xA foo bar 0xfG
I'm done

How do I delete all “words” from the above file which ends with a particular letter (say ‘g’) in each line? The output should be as follows:

This is a test.
One two three
Foo Bar
001 0xA
002 0xA foo bar
I'm done

How do I delete regex-based word using sed or awk under Linux / Unix like operating systems?
[click to continue…]

Sysadmin because even developers need heroes!!!

Sed Find and Display Text Between Two Strings or Words

Q. How do I find the text between the strings FOO and BAR inclusive using sed command line option?
[click to continue…]

Delete text or paragraph between two sections using sed

Q. How do I use sed for selective deletion of certain lines? I have text as follows in file:
Line 1
Line 2
Line 4

I would like to delete all lines between WORD1 and WORD2 to produce final output:
Line 1
Line 2

A. For selective deletion of certain lines sed is the best tool. To print all of file EXCEPT section between WORD1 and WORD2 (2 regular expressions), use
$ sed '/WORD1/,/WORD2/d' input.txt > output.txt

Shell script to remove Javascript code

Here is my small script that reads all *.html files and removes javascript (script download link).

# for loop read each file
for f in $FILES
# replace javascript
sed '/<script type="text\/javascript"/,/<\/script>/d' $INF > $OUTF
/bin/cp $OUTF $INF
/bin/rm -f $OUTF

Above shell script removes all occurrence of javascript.