相关疑难解决方法(0)

如何删除bash中的额外空格?

如何删除变量中的额外空格HEAD

HEAD="    how to  remove    extra        spaces                     "
Run Code Online (Sandbox Code Playgroud)

结果:

how to remove extra spaces
Run Code Online (Sandbox Code Playgroud)

bash

22
推荐指数
5
解决办法
4万
查看次数

如何用只有bash内置函数的字符串中的单个空格替换多个空格

我想用bash用一个空格替换字符串中的多个相邻空格.例:

原始字符串:

"too         many       spaces."
Run Code Online (Sandbox Code Playgroud)

转换字符串:

"too many spaces."
Run Code Online (Sandbox Code Playgroud)

我尝试了类似的东西"${str//*( )/.}",awk '{gsub(/[:blank:]/," ")}1'但我无法做到.

注意:我能够使它工作,<CMD_THAT_GENERATES_THE_INPUT_STRINGH> | perl -lpe's/\s+/ /g'但我不得不使用perl来完成这项工作.我想使用一些bash内部语法而不是调用外部程序,如果可能的话.

string bash shell replace

4
推荐指数
3
解决办法
2441
查看次数

标签 统计

bash ×2

replace ×1

shell ×1

string ×1