To handle specifically those newlines that are in doubly-quoted strings and leave those alone that are outside them, using GNU awk (for RT
):
gawk -v RS='"' 'NR % 2 == 0 { gsub(/
/, "") } { printf("%s%s", $0, RT) }' file
This works by splitting the file along "
characters and removing newlines in every other block. With a file containing
"one",
"three
four",
12,
"seven"
this will give the result
"one",
"threefour",
12,
"seven"
Note that it does not handle escape sequences. If strings in the input data can contain "
, such as "He said: "this is a direct quote.""
, then it will not work as desired.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…