for term in `cat stopwords`; do sed -i 's/\<$term\>//g' spam.txt ;done
鉴于停用词每行包含一个词,而 spam.txt 是纯文本文件,我只需要替换停用词的精确匹配项。没有像我预期的那样表现......
请注意,这两个文件中都包含 doesn't
、couldn't
等词。
最佳答案
您确定要在 for 循环中运行 sed 吗?我会使用 sed 脚本文件。
TMPFILE=mktemp
for WORD in $(cat stopwords); do echo 's/'$WORD'//g' >> $TMPFILE; done
sed -f $TMPFILE spam.txt
rm -f $TMPFILE
关于bash - Sed 就地编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6667835/