在Linux中,sed
是一个非常强大的文本处理工具
sed '/pattern/d' input_file > output_file
这里,/pattern/
是一个正则表达式,用于匹配要删除的行。d
是一个命令,表示删除匹配的行。input_file
是要处理的文件,output_file
是处理后的输出文件。
例如,如果你想要删除一个名为example.txt
的文件中所有包含apple
的行,你可以使用以下命令:
sed '/apple/d' example.txt > example_modified.txt
这将创建一个新的文件example_modified.txt
,其中不包含任何包含apple
的行。如果你想直接修改原始文件,可以使用-i
选项:
sed -i '/apple/d' example.txt
这将直接在example.txt
中删除所有包含apple
的行。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux sed如何删除指定内容的行