Board logo

标题: [文本处理] 批处理代码一样分开使用结果正确 合并后结果不正确求解 [打印本页]

作者: 咒夜坠    时间: 2012-7-30 19:24     标题: 批处理代码一样分开使用结果正确 合并后结果不正确求解

引用代码一和代码二
  1. call 代码一
  2. call 代码二.bat
复制代码
代码一
  1. @echo off
  2. setlocal enableDelayedExpansion
  3. del 50.txt 51.txt 52.txt 50.txt 53.txt 54.txt 55.txt
  4. for /f "delims=: tokens=2" %%i in (原始记录.txt) do echo %%i>>50.txt
  5. for /f "delims=" %%i in (50.txt) do (
  6.     if not defined %%i set %%i=A & echo %%i>>51.txt
  7. )
复制代码
代码二
  1. @echo off
  2. setlocal enableDelayedExpansion
  3. for /f "delims=- tokens=1,2" %%i in (51.txt) do (
  4. @echo %%i>>52.txt
  5. @echo %%j>>52.txt
  6. )
  7. for /f "eol=-" %%i in ('find "6" 52.txt') do echo %%i>>53.txt
  8. for /f "delims=" %%i in (53.txt) do (
  9.     if not defined %%i set %%i=A & echo %%i>>54.txt
  10. )
  11. del 50.txt 51.txt 52.txt 53.txt
  12. pause
复制代码

作者: apang    时间: 2012-7-31 10:44

试试代码一和代码二的最后加上endlocal语句
作者: 咒夜坠    时间: 2014-2-13 15:19

回复 2# apang


    这个问题好像已经很久了
但是当时我是将后2个批处理合并在一起不好用
但是就像现在这样分开却可以正常使用
作者: DAIC    时间: 2014-2-13 16:50

  1. @echo off
  2. del 50.txt 51.txt 52.txt 50.txt 53.txt 54.txt 55.txt
  3. for /f "delims=: tokens=2" %%i in (原始记录.txt) do echo %%i>>50.txt
  4. for /f "delims=" %%i in (50.txt) do (
  5.     if not defined 1_%%i (
  6.         set 1_%%i=A
  7.         echo %%i>>51.txt
  8.     )
  9. )
  10. for /f "delims=- tokens=1,2" %%i in (51.txt) do (
  11.     echo %%i>>52.txt
  12.     echo %%j>>52.txt
  13. )
  14. for /f "eol=-" %%i in ('find "6" 52.txt') do echo %%i>>53.txt
  15. for /f "delims=" %%i in (53.txt) do (
  16.     if not defined 2_%%i (
  17.         set 2_%%i=A
  18.         echo %%i>>54.txt
  19.     )
  20. )
  21. del 50.txt 51.txt 52.txt 53.txt
  22. pause
复制代码





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