如果我有这个...
6,
9,
12
"url": "https://www.url.com"
6,
9,
12
"url": "https://www.url.com"
13,
16
"url": "https://www.url.com"
"url": "https://www.url.com"
18
"url": "https://www.url.com"
"url": "https://www.url.com"
3,
6,
14
"url": "https://www.url.com"
"url": "https://www.url.com"
20
"url": "https://www.url.com"
74
"url": "https://www.url.com"
我如何才能以这种方式加入队伍...
6,9,12"url": "https://www.url.com"
6,9,12"url": "https://www.url.com"
13,16"url": "https://www.url.com"
"url": "https://www.url.com"
18"url": "https://www.url.com"
"url": "https://www.url.com"
3,6,14"url": "https://www.url.com"
"url": "https://www.url.com"
20"url": "https://www.url.com"
74"url": "https://www.url.com"
我尝试使用sed删除以数字开头的行上的换行符,但是它不起作用。我认为是因为线路随着工作而改变了?
sed '/^[0-9]/N;s/\n//'
我明白了...
6,9,
12"url": "https://www.url.com"
6,9,
12"url": "https://www.url.com"
13,16
"url": "https://www.url.com"
"url": "https://www.url.com"
18"url": "https://www.url.com"
"url": "https://www.url.com"
3,6,
14"url": "https://www.url.com"
"url": "https://www.url.com"
20"url": "https://www.url.com"
74"url": "https://www.url.com"
编辑:
感谢您的帮助和解释。
我选择了这个,因为它对我来说更容易理解。他们都工作了。
sed ':a;/https/!{N;ba};s/\n//g'
最佳答案
下面的代码应该工作:
sed ':a;/https/!{N;ba};s/\n//g'
本质上是一个while循环,只要输出的多行确实而不是包含
https
,它就会在一行之后追加一行;只要添加了一行包含https
的行,就会放弃while循环(因为未执行b
命令),并且所有嵌入的换行\n
都会被s
命令删除。更详细地讲,脚本(单引号之间)可以像这样重写:
:a # label you can jump to with a t or b command
/https/!{ # if the line does not match "https" do what's in {…}:
N # append the next line to the current one (putting "\n" in between)
ba # branch to the line labelled as ":a"
}
s/\n//g # change all newlines to empty strings (i.e. remove all newlines for the current multi-line)
相应的伪代码为
begin
while line does not contain "https" {
append another line
}
remove all newlines
关于awk - 在图案处连接线。不均匀的间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60857995/