从WMIC输出删除回车 [英] Removing carriage return from WMIC output

查看:96
本文介绍了从WMIC输出删除回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在批处理文件中使用下面的命令,我与一些相呼应的回车获得输出,但沿。

Using below command in a batch file, i am getting output but along with some echoes as carriage return.

wmic process where Caption='notepad.exe' get ProcessId,WorkingSetSize /Format:Texttable > output.txt

输出:

ProcessId  WorkingSetSize  
4016       6356992         
1548       6189056         

如何摆脱在这个输出回车?

how to get rid of this carriage return in output ?

EDIT1:

参照Foxdrive的工作答案在我的链接的问题我试过下面及其工作不错,但在输出那里传来一个额外的行: ECHO是关闭不知道为什么?

Referring Foxdrive's working answer in my linked question I tried below and its working nice, but in the output there coming an extra line: ECHO is off. don't know why ?

@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  

我要在上面的格式输出只和获取使用的输出:

I want output in above format only and getting that output using:

@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都可以命令在我的系统.. :( ..意志AP preciate您的确认工作.. :)

Is there any trailing CR in output now ? hexdump command is not working in my system..:(..will appreciate your confirmation..:)

推荐答案

这消除了拖尾CR,并提供用空格隔开的值:

This removes the trailing CR and provides the values separated by a space:

@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

该文件的格式如下:

The file is in this format:

624 4923392
9220 4886528

这消除了拖尾CR和CSV格式提供的值

This removes the trailing CR and provides the values in CSV format

@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

这篇关于从WMIC输出删除回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆