Vol*_*gel 55
“删除所有空格”可能意味着不同的事情之一:
0x20。\t”\n”等如果sed出于某种隐藏的原因它不是必需的,最好使用正确的工具来完成这项工作。
该命令tr主要用于将字符列表(因此称为“tr”)转换为其他字符列表。作为一种特殊情况,它可以转换为空字符列表;选项-d( --delete) 将删除出现在列表中的字符。
字符列表可以在[:...:]语法中使用字符类。
tr -d ' ' < input.txt > no-spaces.txttr -d '[:blank:]' < input.txt > no-spaces.txttr -d '[:space:]' < input.txt > no-spaces.txtsed使用 sed 时,[:...:]字符类的语法需要与正则表达式中的字符集的语法结合[...],导致有些混乱[[:...:]]:
sed 's/ //g' input.txt > no-spaces.txtsed 's/[[:blank:]]//g' input.txt > no-spaces.txtsed 's/[[:space:]]//g' input.txt > no-spaces.txt您可以使用它来删除 中的所有空格file:
sed -i "s/ //g" file
Run Code Online (Sandbox Code Playgroud)