码迷,mamicode.com
首页 > 系统相关 > 详细

shell:删除/保留文件中的指定行

时间:2017-09-22 19:08:19      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:指定   shel   color   word   字符   shell   col   定向   保留   

将文件file1中第一行到含有word字符的行删除,并重定向到文件file2:

sed  ‘1,/word/d‘ file1 > file2

将文件file1中含有word字符的行保留,并重定向到文件file2,-n表示结果不打印到屏幕:

sed -n ‘/word/p‘ file1 > file2

将文件file1中>=21行的内容删除,-i表示直接将更改保存在file1:

sed -i ‘21,$d‘  file1

多个条件用分号隔开:

sed  ‘1,/word1/d;21,$d;/word2/d‘  file1 > file2

 

shell:删除/保留文件中的指定行

标签:指定   shel   color   word   字符   shell   col   定向   保留   

原文地址:http://www.cnblogs.com/seaBiscuit0922/p/7576204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!