[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]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. )
复制代码

具体是什么异常呢?
请把你遇到问题时使用的msg.log、long_msg.log、test.bat、以及执行代码之后生成的结果文件打包压缩传上来看看
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

[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

回复 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. )
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表