删除行中的所有空格,但不删除双引号之间的空格

sud*_*roy 5 regex perl awk sed pattern-matching

例:

输入=

This is an example text with    some      spaces. 
This should be 2nd line.
However the spaces between "quotes    should not    change".
last line.
Run Code Online (Sandbox Code Playgroud)

输出=

Thisisanexampletextwithsomespaces. 
Thisshouldbe2ndline.
Howeverthespacesbetween"quotes    should not    change".
lastline.
Run Code Online (Sandbox Code Playgroud)

gle*_*man 5

awk '
    BEGIN {FS = OFS = "\""}
    /^[[:blank:]]*$/ {next}
    {for (i=1; i<=NF; i+=2) gsub(/[[:space:]]/,"",$i)} 
    1
' 
Run Code Online (Sandbox Code Playgroud)
Thisisanexampletextwithsomespaces.
Thisshouldbe2ndline.
Howeverthespacesbetween"quotes    should not    change".
lastline.
Run Code Online (Sandbox Code Playgroud)