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

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

技术教程推荐

玩转Spring全家桶 -〔丁雪丰〕

零基础学Java -〔臧萌〕

Serverless入门课 -〔蒲松洋(秦粤)〕

成为AI产品经理 -〔刘海丰〕

说透芯片 -〔邵巍〕

陈天 · Rust 编程第一课 -〔陈天〕

高并发系统实战课 -〔徐长龙〕

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

零基础GPT应用入门课 -〔林健(键盘)〕

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