我试图找出一种方法来压缩 bash 中不在引号中的空格(双引号和单引号)。我会使用tr -s
,但它不会削减它。我想在文本文件(foo.txt)中有以下行:
" not squeezed " squeeze this part
变成:
" not squeezed " squeeze this part
当然,嵌套单引号、双引号、转义引号会变得更加复杂,所以我想知道是否已经为此编写了某种命令?
编辑:
如果我尝试:
cat foo.txt | tr -s
我会得到输出:
" not squeezed " squeeze this part
这会挤压引号内的空格 - 这是不可取的