Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed in place edit

Tags:

bash

sed

for term in `cat stopwords`; do sed -i 's/\<$term\>//g' spam.txt ;done

Given stopwords contains a word per line and spam.txt is plain text file, I just need to replace exact matches of stopwords. Does not behave as I expect ... Note there are words like doesn't, couldn't in both the files.

like image 277
Tathagata Avatar asked Jul 12 '11 16:07

Tathagata


1 Answers

Are you sure you want to run sed in for loop? I would use sed script-file.

TMPFILE=mktemp
for WORD in $(cat stopwords); do echo 's/'$WORD'//g' >> $TMPFILE; done
sed -f $TMPFILE spam.txt
rm -f $TMPFILE
like image 188
Sami Kerola Avatar answered Oct 20 '22 05:10

Sami Kerola