我有一个文本文件,其中的内容包含大量NUL或数据之间的空格:
[null] [null] [null] [null]名称[null] [null] [null] [null] [null] [null]姓
文本文件中的数据总是不同的。
我已经搜索并测试了/ F的许多类似问题,它们在(“%file%”)中使用“ usebackq delims =” %% a“来回显%% a和类似的命令,但是我总是得到空结果。
有人可以帮忙吗?
如果您确实拥有一个文本文件,例如,以下内容:
而且,您只想NUL
在正常For /F
循环文件读取过程中忽略字符,则可以从批处理文件中向powershell寻求帮助:
@For /F "Delims=" %%G In (
'%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe ^
-Nologo -NoProfile -Command "(Get-Content 'sourcefile.txt')" ^
" -replace '\x00',''"') Do @Echo(%%G
@Pause
为了方便阅读,我将长行分割为多个,但您也可以将其作为一行批处理文件:
@(For /F "Delims=" %%G In ('%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -Nologo -NoProfile -Command "(Get-Content 'sourcefile.txt') -replace '\x00',''"') Do @Echo(%%G) & Pause
并直接从命令提示符cmd进行简单说明:
For /F "Delims=" %G In ('powershell -NoP "(GC 'sourcefile.txt') -replace '\x00',''"') Do @Echo(%G
[编辑/]
如果你想添加一个COM米一个,在你所提供的具体例子这两个特定的词,和我在链接的图像使用上面之间,那么,这将是可能的。
例如,您可以在PowerShell部分中通过更改以下内容来完成此操作:
-replace '\x00',''
至 -replace ' ',', ' -replace '\x00',''
或者,您可以通过更改For
循环选项来做到这一点:
"Delims="
至 "Tokens=1*"
然后更改:
@Echo(%%G
, 要么 @Echo(%G
至:
@Echo(%%G, %%H
或@Echo(%G, %H
分别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句