Board logo

标题: [文本处理] [已解决]给BAT代码增加排除包含字符===的行 [打印本页]

作者: wh1234567    时间: 2012-7-19 15:39     标题: [已解决]给BAT代码增加排除包含字符===的行

for /f %%a in ('type a.txt^|find /c /v ""')do set old=%%a
如何给上面的代码里增加一个排除包含字符===的行的功能?
例如
不统计文本里包含===的行
注意不得破坏代码原有的功能
作者: wudixin96    时间: 2012-7-19 16:22

为啥不直接把find 查找里输入===???
作者: apang    时间: 2012-7-19 19:14

注意不得破坏代码原有的功能

代码本来就不完整,想破坏都无从下手咧
试试在""之间填上三个等于符号。。。
作者: wh1234567    时间: 2012-7-19 19:26

试过,不行
作者: wh1234567    时间: 2012-7-19 21:33

回复 3# apang


    @echo off

set outfile=a.txt

for /f %%a in ('type a.txt^|find /c /v "=="')do set old=%%a

echo %date% %time%>>a.txt
echo ======2313131323====>>a.txt
echo 000%date% %time%>>a.txt
echo ==000000000===>>a.txt

for /f %%a in ('type a.txt^|find /c /v "=="')do set b1=%%a

echo 新增行内容:
set /a new=%b1%-%old%
if %old% neq %b1% (
        more +%old% %outfile%&&echo 新增%new%行
) 2>nul
pause

可排除,但是echo 新增行内容:这里会显示错误,不准确
作者: apang    时间: 2012-7-19 23:22

  1. @echo off
  2. ::set outfile=a.txt
  3. if not exist a.txt cd.>a.txt
  4. for /f %%a in ('find /c /v ""^<a.txt') do set old=%%a
  5. echo %date% %time%>>a.txt
  6. echo ======2313131323====>>a.txt
  7. echo 000%date% %time%>>a.txt
  8. echo ==000000000===>>a.txt
  9. echo 新增行内容:
  10. more +%old% a.txt
  11. for /f %%a in ('more +%old% a.txt^|find /c /v "=="') do (
  12.   echo 新增%%a行
  13. )
  14. pause
复制代码

作者: wh1234567    时间: 2012-7-20 00:01

本帖最后由 wh1234567 于 2012-7-20 00:22 编辑

回复 6# apang


    不想让带==的行在新增行内容下显示出来
作者: garyng    时间: 2012-7-20 00:16

还是建议楼主把txt的内容放上来吧。。。
作者: apang    时间: 2012-7-20 00:23

回复 7# wh1234567

呃,真受不了你,挤牙膏似的。。。
第10行改改more +%old% a.txt|find /v "=="
再不行,偶放弃。。。
作者: poter    时间: 2012-7-20 21:08

可以先用findstr把包含===的行排除,再嵌循环




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