过滤批处理文件cmd输出到文件

时间:2018-05-02 11:39:02

标签: batch-file filtering

我运行下面的脚本来显示我们服务器的所有当前连接,有没有办法在写入文件时过滤它而只提供活动会话?

@ECHO OFF
REM Delete previous output file
del currentsessions.txt
FOR /F "delims=," %%i IN (AXServers.txt) DO (
echo %%i >> currentsessions.txt
QUERY SESSION /SERVER:%%i >> currentsessions.txt
)

并且输出如下

QuerySessionsResult

1 个答案:

答案 0 :(得分:0)

根据npocmaka发表评论,调整为以下代码。

@ECHO OFF
REM Delete previous output file
del currentsessions.txt
FOR /F "delims=," %%i IN (AXServers.txt) DO (
echo %%i >> currentsessions.txt
QUERY SESSION /SERVER:%%i|find "Active" >> currentsessions.txt
)