我想遍历文件并删除某些行。示例文件:
test.txt
a
b
c
d
我有的:
FILE=/tmp/test.txt
while read FILE
do
# if the line starts with b delete it otherwise leave it there
?
done
这是一项工作sed
-UNIX流编辑器:
(sed '/^b/d' yourfile > yourfile~ && mv yourfile~ yourfile) || rm yourfile~
该命令将删除所有以a开头的行,并将其余的行b
写入备份文件。如果成功,则备份文件将重命名为原始文件;如果失败,则将删除备份文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句