我希望使用sed
(或将其与另一个grep
命令组合)来转换以下字符串
John: Hi!,How are you,?,Dylan: Hey,OK
进入之内
John: Hi!
John: How are you
John: ?
Dylan: Hey
Dylan: OK
如果不可能的话我愿意妥协
John: Hi!,How are you,?
Dylan: Hey,OK
非常感谢
最佳答案
sed
可以使用。
有一个很棒的Sed - An Introduction and Tutorial by Bruce Barnett在线页面,我在编写sed
脚本时总是打开它。
尝试一下:
printf 'John: Hi!,How are you,?,Dylan: Hey,OK\n' | sed -n '
:1
/./ {
/^[^:,][^:,]*: / {
h
s/^\([^:,][^,:]*: \).*$/\1/
x
s/,/\n/
P
D
}
x
/./ {
x
H
x
s/\n//g
x
s/.//g
x
b 1
}
}'
输出为:
John: Hi!
John: How are you
John: ?
Dylan: Hey
Dylan: OK
关于bash - sed分成几行(高级),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53334047/