从WMIC输出中删除回车
问题描述:
在批处理文件中使用下面的命令,我得到输出,但还有一些回声作为回车。从WMIC输出中删除回车
wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable > output.txt
输出:
ProcessId WorkingSetSize
4016 6356992
1548 6189056
如何摆脱在输出这个回车?
EDIT1:
参考Foxdrive的工作答案在我的链接的问题我下面尝试及其工作不错,但在输出那里传来一个额外的行:ECHO处于关闭状态。不知道为什么?
@echo off
setlocal enabledelayedexpansion
(For /F "tokens=1,* delims==" %%A in (' "wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable" ') do (
set "line=%%A %%B"
set "line=!line:~0,-1!"
echo !line!
))>output.txt
output.txt中:
ProcessId WorkingSetSize
4768 6365184
5608 5500928
2888 6037504
1052 5472256
ECHO is off.
EDIT2:
ProcessId WorkingSetSize
4768 6365184
5608 5500928
2888 6037504
1052 5472256
我想在上面的格式输出只和获得使用输出:
@echo off
setlocal enabledelayedexpansion
(For /F "delims=" %%A in ('"wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /format:Texttable |findstr "[0-9P]" "') do (
set "line=%%A"
echo !line:~0,-1!
)) > output.txt
现在输出中是否有任何尾随CR? hexdump都可以命令没有在我的系统工作.. :(..会感谢您的确认.. :)
答
这消除了拖尾CR和提供用空格隔开的值:
@echo off
setlocal enabledelayedexpansion
(For /F "tokens=2,3 delims=," %%a in ('"wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /format:csv |findstr "[0-9]" "') do (
set "num=%%b"
echo %%a !num:~0,-1!
))>output.txt
该文件是以下格式:
624 4923392
9220 4886528
这消除尾随CR,并提供以CSV格式的值
@echo off
setlocal enabledelayedexpansion
(For /F "delims=" %%A in ('"wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /format:csv |findstr "[0-9]" "') do (
set "line=%%A"
echo !line:~0,-1!
))>output.txt
这是格式文件是:
PCNAME,956,4960256
PCNAME,4004,4870144
的
+0
@ Foxi ..感谢..!这两个代码在我的系统上运行良好..请问您可以确认** EDIT2 **问题..? – Sunny
答
试试这个:
wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable|findstr /v "^$">file.txt
输出是(Windows 8中)远离'太可怕了”:
C:\Users\Private\TEST>wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable|findstr /v "^$">file.txt C:\Users\Private\TEST>type file.txt ProcessId WorkingSetSize 8896 8142848 C:\Users\Private\TEST>hexdump -C file.txt 00000000 50 72 6f 63 65 73 73 49 64 20 20 57 6f 72 6b 69 |ProcessId Worki| 00000010 6e 67 53 65 74 53 69 7a 65 20 20 0d 0d 0a 38 38 |ngSetSize ...88| 00000020 39 36 20 20 20 20 20 20 20 38 31 34 32 38 34 38 |96 8142848| 00000030 20 20 20 20 20 20 20 20 20 0d 0d 0a | ...| 0000003c C:\Users\Private\TEST>for /f "tokens=*" %a in (file.txt) do @echo %a ProcessId WorkingSetSize 8896 8482816 C:\Users\Private\TEST>(for /f "tokens=*" %a in (file.txt) do @echo %a)|hexdump -C 00000000 50 72 6f 63 65 73 73 49 64 20 20 57 6f 72 6b 69 |ProcessId Worki| 00000010 6e 67 53 65 74 53 69 7a 65 20 20 0d 20 0a 38 38 |ngSetSize . .88| 00000020 39 36 20 20 20 20 20 20 20 38 34 38 32 38 31 36 |96 8482816| 00000030 20 20 20 20 20 20 20 20 20 0d 20 0a | . .| 0000003c
答
我有运行代码没有多余的CR或aditional的回声。但是,既然你得到了他们,Endoro的回答就够了。而不是试图不期望的线路进行筛选,试图让只有你有兴趣
wmic ..... ^| findstr /B /R "[0-9P]"
只有一个数字(数据)或P(的ProcessID)开始的行线
可能重复的[编辑WMIC输出格式](HTTP://计算器.com/questions/19462042/editing-wmic-output-format) – nephi12
@foxidrive请参阅** EDIT1 **问题.. :) – Sunny
是的..我需要这些值在第二个脚本中,但是当一个额外的CR来在输出中,第二个脚本不起作用。 – Sunny