input =
This is an example text with some spaces.
This should be 2nd line.
However the spaces between "quotes should not change".
last line.
output =
Thisisanexampletextwithsomespaces.
Thisshouldbe2ndline.
Howeverthespacesbetween"quotes should not change".
lastline.
awk '
BEGIN {FS = OFS = "\""}
/^[[:blank:]]*$/ {next}
{for (i=1; i<=NF; i+=2) gsub(/[[:space:]]/,"",$i)}
1
'
Thisisanexampletextwithsomespaces.
Thisshouldbe2ndline.
Howeverthespacesbetween"quotes should not change".
lastline.
Example with GNU sed:
$sed -r 's/(\".*\")|\s*/\1/g' file Thisisanexampletextwithsomespaces. Thisshouldbe2ndline. Howeverthespacesbetween"quotes should not change". lastline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With