windows windows命令行:如何删除文件中的空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3242856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
windows command line: how to remove space in file
提问by Hyman
In linux, we can do it with tr command to remove space. How can I do it in windows? I like to remove space in each line of a text file from command line in Windows XP. Thanks.
在 linux 中,我们可以使用 tr 命令来删除空间。我怎样才能在windows中做到这一点?我喜欢从 Windows XP 的命令行中删除文本文件每一行中的空格。谢谢。
回答by BenV
Here's a windows shell script example from http://www.dostips.com/DtTipsStringManipulation.php#Snippets.RemoveSpaces
这是来自http://www.dostips.com/DtTipsStringManipulation.php#Snippets.RemoveSpaces的 Windows shell 脚本示例
set str= word &rem
echo."%str%"
set str=%str: =%
echo."%str%"
回答by Scott Stafford
You'll need a scripting language (Powershell, Python, Perl...) or use tr via Cygwin.
您将需要一种脚本语言(Powershell、Python、Perl...)或通过 Cygwin 使用 tr。
回答by Rob Moore
Why not just use "SET filter=%*" to remove leading and trailing spaces?
为什么不直接使用“SET filter=%*”来删除前导和尾随空格?
@ECHO Off
SET source= 1 2 3 4 5
ECHO Source string = "%source%"
CALL :SpaceCut %source%
ECHO Beginning and ending spaces removed = "%filter%"
pause
exit /b
:SpaceCut
SET filter=%*
exit /b