"但不添加两个连续行?-6ren"> "但不添加两个连续行?-考虑这个示例文件: 01 00:00:00,000 --> 00:00:00,000 Alphabetic characters. 02 00:00:00,000 --> 00:00:00,000 A-6ren">
gpt4 book ai didi

linux - 如何在包含模式 [ :alpha:], 的任何行之前添加字符串 ""但不添加两个连续行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:55 27 4
gpt4 key购买 nike

考虑这个示例文件:

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,

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

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,

使用 sed: sed '/[[:alpha:]]/s/^//' 文件 >new_file

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

最佳答案

$ awk '!f && /[[:alpha:]]/{print "<fc=ff00>" $0; f=1; next} {print; f=0}' file
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,

关于linux - 如何在包含模式 [ :alpha:], 的任何行之前添加字符串 "<fc=ff00>"但不添加两个连续行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40728658/

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