码迷,mamicode.com
首页 > 其他好文 > 详细

【sed】常用命令

时间:2018-08-02 18:19:31      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:ctrl+v   color   style   bsp   常用   hello   ctrl   class   col   

替换

替换某一整行

sed 1c hello test   #将第一行替换为hello

 

str1替换为str2

sed  s/^str1.*/str2/  filename  #以str1开头
sed  s/.*str1$/str2/  filename   #以str1结尾
sed  s/.*str1.*/str2/  filename  #含有str1

 

将含有xhn的行中的str1替换为str2

sed  ‘/xhn/s/str1/str2/g’ test

 

将1-5行替换为两行:

hello

world

 sed 1,5c hello\nworld test

 

删除

删除空行

sed /^ *$/d test #只能删除没有特殊字符的空行
sed /[[:space:]]*/d test #可删除特殊字符
特别需要说明一下,linux中的^M是ctrl+v和ctrl+m打出来的

 

【sed】常用命令

标签:ctrl+v   color   style   bsp   常用   hello   ctrl   class   col   

原文地址:https://www.cnblogs.com/xhnxhnu/p/9408704.html

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