gpt4 book ai didi

linux - 如何在以 开头的行后添加字符串 “”,但不添加连续的两行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:06:02 25 4
gpt4 key购买 nike

考虑这个示例文件:

01
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters.
02
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters
Alphabetic characters,
03
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters,

我只想在一行文本中添加字符串。

01
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters.</font>
02
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters
Alphabetic characters,</font>
03
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters,</font>

我不清楚如何排除第一行。有什么建议吗?

最佳答案

这就是我认为你真正想要做的:

$ cat file
01
00:00:00,000 --> 00:00:00,000
Alphabetic characters.
02
00:00:00,000 --> 00:00:00,000
Alphabetic characters
Alphabetic characters,
03
00:00:00,000 --> 00:00:00,000
Alphabetic characters,

$ cat tst.awk
/^[[:alpha:]]/ { buf = (buf ? buf RS : "") $0; next }
buf { printf "<fc=ff00>%s</font>\n", buf; buf="" }
{ print }
END { if (buf) printf "<fc=ff00>%s</font>\n", buf }

$ awk -f tst.awk file
01
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters.</font>
02
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters
Alphabetic characters,</font>
03
00:00:00,000 --> 00:00:00,000
<fc=ff00>Alphabetic characters,</font>

关于linux - 如何在以 <fc=ff00> 开头的行后添加字符串 “</font>”,但不添加连续的两行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40792574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com