我必须对几个字符串执行多个操作才能对其进行清理。我已经能够这样做,但是在 bash
中以
# Getting the Content between START and END
var1=$(sed '/START/,/END/!d;//d' <<< "$content")
# Getting the 4th Line
var2=$(sed '4q;d' <<< "$content")
# Stripping all the new lines
var1=${var1//$'\n'/}
var2=${var2//$'\n'/}
# Escaping the double quotes i.e. A"B => A\"B
var1=$(sed "s/\"/\\\\\"/g" <<< "$var1")
var2=$(sed "s/\"/\\\\\"/g" <<< "$var2")
# Removing the contents wrapped in brackets i.e. A[...]B => AB
var1=$(sed -e 's/\[[^][]*\]//g' <<< "$var1")
var2=$(sed -e 's/\[[^][]*\]//g' <<< "$var2")
毫无疑问,当一次操作可以完成一次又一次的阅读时,这是非常糟糕的。 有什么建议吗?
工作示例:
SAMPLE INPUT
[1][INTRO]
[2][NAV]
ABAQUEsnE,Masséot
...
START
French ceramist,who was the first grand-master of the glazed pottery
at Sotteville-ls-Rouen (20 years before [8]bernard Palissy). He took
part in the development of the ceramic factory of Rouen. He was the
author - among others - of the ceramic triptych representing the Flood
(1550,couen,Muse de la Renaissance).
END
DESIRED OUTPUT
ABAQUEsnE,Masséot
French ceramist,who was the first grand-master of the glazed pottery at Sotteville-ls-Rouen (20 years before bernard Palissy). He took part in the development of the ceramic factory of Rouen. He was the author - among others - of the ceramic triptych representing the Flood (1550,Muse de la Renaissance).