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

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

技术教程推荐

数据结构与算法之美 -〔王争〕

如何设计一个秒杀系统 -〔许令波〕

人人都能学会的编程入门课 -〔胡光〕

分布式协议与算法实战 -〔韩健〕

职场求生攻略 -〔臧萌〕

Web安全攻防实战 -〔王昊天〕

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

大厂设计进阶实战课 -〔小乔〕

零基础学Python(2023版) -〔尹会生〕

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