[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理空行和指定字符多条件判断,现在是空行判断异常

C盘
msg.log
1 abc error : xxx

long_msg.log
1

两个文件,判断long_msg.log为空,或首行第一列为abc error或 null 或NULL ,则把msg.log的内容追加写到msg_append.log,如果long_msg.log不满足前面的条件,则把long_msg.log的内容追加写到msg_append.log
  1. for /f "tokens=1* delims=:" %%i in ('findstr /i ".*" c:\msg.log') do (
  2. if "%%i" == "" (
  3.    type c:\msg.log >> c:\msg_append.log
  4. ) else (
  5. if "%%i" == "abc error" (
  6.    type c:\msg.log >> c:\msg_append.log
  7. ) else (
  8. if "%%i" == "null" (
  9.    type c:\msg.log >> c:\msg_append.log
  10. ) else (
  11. if "%%i" == "NULL" (
  12.    type c:\msg.log >> c:\msg_append.log
  13. ) else (
  14.   type c:\long_msg.log >> c:\msg_append.log
  15. )
  16. )
  17. )
  18. )
复制代码

[attach]12104[/attach]

TOP

回复 2# Batcher

前面说错,是判断long_msg.log文件是不是有空行或有特定的关键字符,如果命中了,就把msg.log的内容写到msg_append.log中。

TOP

现在的问题是如果long_msg.log为空行时,不能把msg.log写到msg_append.log中。

TOP

long_msg.log 的内容是变化的,如为abc error或 null 或NULL,或空行,或其他内容。现在是空行判断不出来。

TOP

回复 2# Batcher


  能帮忙看看吗,谢谢。

TOP

返回列表