Board logo

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

作者: 36876660@qq.com    时间: 2019-8-6 16:47     标题: 批处理空行和指定字符多条件判断,现在是空行判断异常

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. )
复制代码

作者: Batcher    时间: 2019-8-6 17:20

具体是什么异常呢?
请把你遇到问题时使用的msg.log、long_msg.log、test.bat、以及执行代码之后生成的结果文件打包压缩传上来看看
作者: 36876660@qq.com    时间: 2019-8-10 22:23

[attach]12104[/attach]
作者: 36876660@qq.com    时间: 2019-8-10 22:25

回复 2# Batcher

前面说错,是判断long_msg.log文件是不是有空行或有特定的关键字符,如果命中了,就把msg.log的内容写到msg_append.log中。
作者: 36876660@qq.com    时间: 2019-8-10 22:26

现在的问题是如果long_msg.log为空行时,不能把msg.log写到msg_append.log中。
作者: 36876660@qq.com    时间: 2019-8-13 08:45

long_msg.log 的内容是变化的,如为abc error或 null 或NULL,或空行,或其他内容。现在是空行判断不出来。
作者: 36876660@qq.com    时间: 2019-8-14 09:55

回复 2# Batcher


  能帮忙看看吗,谢谢。
作者: Batcher    时间: 2019-8-14 11:49

回复 6# 36876660@qq.com
  1. @echo off
  2. for /f "tokens=1* delims=:" %%i in ('findstr /n ".*" c:\long_msg.log') do (
  3.     if "%%j" == "NULL" (
  4.         echo c:\msg.log
  5.         type c:\msg.log >> c:\msg_append.log
  6.     ) else if "%%j" == "abc error" (
  7.         echo c:\msg.log
  8.         type c:\msg.log >> c:\msg_append.log
  9.     ) else if "%%j" == "null" (
  10.         echo c:\msg.log
  11.         type c:\msg.log >> c:\msg_append.log
  12.     ) else if "%%j" == "" (
  13.         echo c:\msg.log
  14.         type c:\msg.log >> c:\msg_append.log
  15.     ) else (
  16.         echo c:\long_msg.log 5
  17.         type c:\long_msg.log >> c:\msg_append.log
  18.     )
  19. )
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2