Tim*_*Tim 0 python regex perl awk sed
我想知道如何转换类似于以下内容的文本:
Chapter 3 Convex Functions 97
3.1 Definitions 98
3.2 Basic Properties 103
Run Code Online (Sandbox Code Playgroud)
至:
("Chapter 3 Convex Functions 97" "#97")
("3.1 Definitions 98" "#98")
("3.2 Basic Properties 103" "#103")
Run Code Online (Sandbox Code Playgroud)
通过使用一些方便但功能强大的文本操作语言和/或实用程序,如sed,awk,regex,perl,python,...
感谢致敬!
注意:在每一行中,重复最后一个数字.
这是一个Perl解决方案:
while (<DATA>) {
s/^(.+ (\d+))$/("$1" "#$2")/;
print;
}
__DATA__
Chapter 3 Convex Functions 97
3.1 Definitions 98
3.2 Basic Properties 103
Run Code Online (Sandbox Code Playgroud)
打印:
("Chapter 3 Convex Functions 97" "#97")
("3.1 Definitions 98" "#98")
("3.2 Basic Properties 103" "#103")
Run Code Online (Sandbox Code Playgroud)
或作为一个班轮:
perl -pe 's/^(.+ (\d+))$/("$1" "#$2")/'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
143 次 |
| 最近记录: |