删除文本文件中包含特定字符串的行如何使用sed删除文本文件中包含特定字符串的所有行?
3 回答

开心每一天1111
TA贡献1836条经验 获得超13个赞
sed '/pattern to match/d' ./infile
sed -i '/pattern to match/d' ./infile
sed -i.bak '/pattern to match/d' ./infile
sed -i '' '/pattern/d' ./infile

眼眸繁星
TA贡献1873条经验 获得超9个赞
sed
:
AWK
awk '!/pattern/' file > temp && mv temp file
Ruby(1.9+)
ruby -i.bak -ne 'print if not /test/' file
Perl
perl -ni.bak -e "print unless /pattern/" file
shell(bash 3.2及更高版本)
while read -r linedo [[ ! $line =~ pattern ]] && echo "$line"done <file > o mv o file
GNUgrep
grep -v "pattern" file > temp && mv temp file
sed
sed -n '/pattern/!p' file

繁花如伊
TA贡献2012条经验 获得超12个赞
sed -i '/pattern/d' filename
grep -v "pattern" filename > filename2; mv filename2 filename
添加回答
举报
0/150
提交
取消