Sed - 分支操作

Sed - 分支操作 首页 / Sed入门教程 / Sed - 分支操作

可以使用 t 命令创建分支。仅当上一个命令成功时, t 命令才会跳转到标签。让无涯教程以与上一章相同的示例为例,但是现在不打印单个连字符(-),而是打印四个连字符。以下示例说明了 t 命令的用法。

[jerry]$sed -n ' 
h;n;H;x 
s/\n/,/
:Loop 
/Paulo/s/^/-/
/----/!t Loop 
p' books.txt 

执行以上代码后,将产生以下输出。

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/sed/sed-branches.html

来源:LearnFk无涯教程网

A Storm of Swords, George R. R. Martin 
The Two Towers, J. R. R. Tolkien 
----The Alchemist, Paulo Coelho 
The Fellowship of the Ring, J. R. R. Tolkien 
----The Pilgrimage, Paulo Coelho 
A Game of Thrones, George R. R. Martin

为了提高可读性,每个SED命令都写在单独的行上。否则,可以编写一个单线SED,如下所示:

[jerry]$sed -n 'h;n;H;x; s/\n/, /; :Loop;/Paulo/s/^/-/; /----/!t Loop; p' books.txt 

执行以上代码后,将产生以下输出。

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/sed/sed-branches.html

来源:LearnFk无涯教程网

A Storm of Swords, George R. R. Martin 
The Two Towers, J. R. R. Tolkien 
----The Alchemist, Paulo Coelho 
The Fellowship of the Ring, J. R. R. Tolkien 
----The Pilgrimage, Paulo Coelho 
A Game of Thrones, George R. R. Martin

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出计算机组成原理 -〔徐文浩〕

数据中台实战课 -〔郭忆〕

编译原理实战课 -〔宫文学〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

高楼的性能工程实战课 -〔高楼〕

技术面试官识人手册 -〔熊燚(四火)〕

Web漏洞挖掘实战 -〔王昊天〕

Serverless进阶实战课 -〔静远〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)