You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Windows批处理脚本跳过Logging.csv前两行对比主机名

批处理脚本修改:跳过Logging.csv前两行匹配主机名

原脚本通过findstr直接检索整个Logging.csv文件,要实现跳过前两行的需求,可以借助more +2命令先过滤掉Logging.csv的前两行,再将剩余内容传给findstr进行匹配。

修改后的完整脚本如下:

@echo off
setlocal enabledelayedexpansion
for /f "skip=1" %%e in (hostname.csv) do (
    type logging.csv | more +2 | findstr /i "%%e" >nul
    if errorlevel 1 (
        echo !date! !time!: Node %%e has NOT reported in the last 24 hours >> missing.txt
        echo !date! !time!: Node %%e has NOT reported in the last 24 hours
    ) else (
        echo !date! !time!: Node %%e reported in the last 24 hours >> found.txt
    )
)
endlocal

关键改动说明:

  • 新增setlocal enabledelayedexpansion和endlocal,将%date%、%time%改为!date!、!time!,解决原脚本循环中日期时间值不更新的隐患
  • 用type logging.csv | more +2 | findstr /i "%%e"替代原有的findstr /i "%%e" logging.csv:
    • more +2会跳过Logging.csv的前两行,仅输出第三行及以后的内容
    • 通过管道将过滤后的内容传给findstr,确保只在有效日志行中匹配主机名
  • 移除原脚本中多余的echo ... | echo ...写法,直接拆分两行输出即可

内容的提问来源于stack exchange,提问作者earthworm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 13:50:39