当前位置: 首页 > news >正文

南宁建站模板展示淮北网站开发公司

南宁建站模板展示,淮北网站开发公司,深圳企业网站建设开发费用,哪个网站平面设计做的好0 前言 在 Linux shell编程学习笔记73:sed命令——沧海横流任我行(上)-CSDN博客文章浏览阅读684次,点赞32次,收藏24次。在大数据时代,我们要面对大量数据,有时需要对数据进行替换、删除、新增、…

 

0 前言

 在

Linux shell编程学习笔记73:sed命令——沧海横流任我行(上)-CSDN博客文章浏览阅读684次,点赞32次,收藏24次。在大数据时代,我们要面对大量数据,有时需要对数据进行替换、删除、新增、选取等特定工作。在Linux中提供很多数据处理命令,如果我们要以行为单位进行数据处理,可以使用sed命令。https://blog.csdn.net/Purpleendurer/article/details/141307421?spm=1001.2014.3001.5501中,我们研究了sed的基础知识。

Linux shell编程学习笔记74:sed命令——沧海横流任我行(中)-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/Purpleendurer/article/details/141369789?spm=1001.2014.3001.5501中,我们见识了sed删除和替换功能的威力。

现在我们通过一些实例来见识一下sed插入等功能的威力。

1 sed实列

1.1 插入行

1.1.1 前插

我们可以使用i命令(insert)来完成前插。 

1.1.1.1 在第3行、第4行前插入'abc'

命令为:

sed '3,4i\abc'

其中sed命令的参数说明如下:

3,4 :指定第3行、第4行

i:在前插入命令

\abc:要插入的字符串

[purpleendurer @ bash ~]  seq 7 | cat -n1  12  23  34  45  56  67  7
[purpleendurer @ bash ~]  seq 7 | cat -n | sed '3,4i\abc'1  12  2
abc3  3
abc4  45  56  67  7
[purpleendurer @ bash ~] 

1.1.1.2 在开头前插入'abc'

命令为:

sed -e '1i\abc'

其中sed命令的参数说明如下:

-e:解释脚本

1 :指定第1行

i:在前插入命令

\abc:要插入的字符串

[purpleendurer @ bash ~]  seq 7 | cat -n1  12  23  34  45  56  67  7
[purpleendurer @ bash ~]  seq 7 | cat -n | sed -e '1i\abc'
abc1  12  23  34  45  56  67  7
[purpleendurer @ bash ~] 

 

 

1.1.1.3 在所有包含1的行前插入'abc' 

命令为:

 sed  '/1*/i\abc'

[purpleendurer @ bash ~] seq 11 | cat -n 1  12  23  34  45  56  67  78  89  910  1011  11
[purpleendurer @ bash ~] seq 11 | cat -n | sed  '/1*/i\abc'
abc1  1
abc2  2
abc3  3
abc4  4
abc5  5
abc6  6
abc7  7
abc8  8
abc9  9
abc10  10
abc11  11
[purpleendurer @ bash ~] 

 

 1.1.2 追加(后插)

我们可以使用a命令(append)来完成追加(后插)。 

1.1.2.1在第3行及其后2行后追加'abc'

命令为:

sed '3,+2a\abc'

[purpleendurer @ bash ~]  seq 7 | cat -n1  12  23  34  45  56  67  7
[purpleendurer @ bash ~]  seq 7 | cat -n | sed '3,+2a\abc'1  12  23  3
abc4  4
abc5  5
abc6  67  7
[purpleendurer @ bash ~] 

 

1.1.2.2 在末尾追加'abc'

命令为:

sed '$a\abc'

[purpleendurer @ bash ~]  seq 7 | cat -n1  12  23  34  45  56  67  7
[purpleendurer @ bash ~]  seq 7 | cat -n | sed '$a\abc'1  12  23  34  45  56  67  7
abc
[purpleendurer @ bash ~] 

1.1.2.3 在偶数行后追加2行信息,第1行是abc,第2行是def

命令为:

sed  '0~2a\abc\
def
'

[purpleendurer @ bash ~] seq 5 | cat -n1  12  23  34  45  5
[purpleendurer @ bash ~] seq 5 | cat -n | sed  '0~2a\abc\
def'1  12  2
abc
def3  34  4
abc
def5  5
[purpleendurer @ bash ~] 

 

1.1.2.4 在所有包含1的行后面追加abc

命令为:

 sed '/1/aabc'

 

[purpleendurer @ bash ~] seq 10 | cat -n1  12  23  34  45  56  67  78  89  910  10
[purpleendurer @ bash ~] seq 10 | cat -n | sed '/1/aabc'1  1
abc2  23  34  45  56  67  78  89  910  10
abc
[purpleendurer @ bash ~] 

1.1.2.5 在只含有1个1的行后面追加abc 

命令为:

 sed '/1$/aabc'

[purpleendurer @ bash ~] seq 10 | cat -n1  12  23  34  45  56  67  78  89  910  10
[purpleendurer @ bash ~] seq 10 | cat -n | sed '/1$/aabc'1  1
abc2  23  34  45  56  67  78  89  910  10
[purpleendurer @ bash ~] 

 

1.2 打印行号

我们可以使用等号(=)来代表行号。

命令为:

 sed  '='

 

[purpleendurer @ bash ~] echo "aaa" >  t.txt
[purpleendurer @ bash ~] echo "bbb" >> t.txt
[purpleendurer @ bash ~] echo "ccc" >> t.txt
[purpleendurer @ bash ~] cat t.txt
aaa
bbb
ccc
[purpleendurer @ bash ~] sed '=' t.txt
1
aaa
2
bbb
3
ccc
[purpleendurer @ bash ~] 

http://www.yayakq.cn/news/637225/

相关文章:

  • 汕头网站建设stqhcx在QQ上做cpa网站说是恶意的
  • 四川省工程建设协会网站网站app程序制作企业
  • 网站建设流程域名申请响应式网站展示型
  • 城市建设学校网站管理规章制度建筑公司组织架构
  • 一个域名可以建设几个网站江门小程序制作
  • 报名网站建设定做前旗网站开发营销
  • 云南昆明网站设计怎么编写app软件
  • 前端网页模板优化网站建设人员组成
  • 用模版做网站的好处和坏处吉林省吉林市
  • 在哪里做网站比较好免费创建自己app平台
  • 带做网站绿标做境外碎片化旅游的网站
  • 提示网站正在建设中广西城乡建设部网站首页
  • 中国空间站名字国内免费云服务器推荐
  • 北京官方网站怎么做Wordpress排版混乱
  • 企查查免费下载安装seo关键词如何设置
  • 产品介绍网站设计怎么在ps做网站首页
  • 企业建设网站有哪些wordpress js链接
  • 开源程序做网站任务商场网站开发的项目分析
  • 哪些网站需要做分享按钮做网站 广告 备案
  • 室内设计和网站建设哪个前景好书店网站模板下载
  • 阿坝网站制作android移动网站开发详解
  • 邢台专业做移动网站邢台有什么网络公司
  • 淮南市重点工程建设管理局网站公众号网页制作软件
  • 支付建设网站的费用什么科目电子版个人简历模板
  • 机械英文网站大连金州区房价
  • 产品review网站怎么做百度关键词排名用什么软件
  • 手机网站设计报告模板做企业网站有什么好处
  • 网站开发 报价单广告主
  • 旅游网站的建设依据和背景一起做英语网站
  • 英文网站站长工具wordpress 大赛 投票