标题: [文本处理] 批处理代码一样分开使用结果正确 合并后结果不正确求解 [打印本页]
作者: 咒夜坠 时间: 2012-7-30 19:24 标题: 批处理代码一样分开使用结果正确 合并后结果不正确求解
引用代码一和代码二复制代码
代码一- @echo off
- setlocal enableDelayedExpansion
- del 50.txt 51.txt 52.txt 50.txt 53.txt 54.txt 55.txt
- for /f "delims=: tokens=2" %%i in (原始记录.txt) do echo %%i>>50.txt
- for /f "delims=" %%i in (50.txt) do (
- if not defined %%i set %%i=A & echo %%i>>51.txt
- )
复制代码
代码二- @echo off
- setlocal enableDelayedExpansion
- for /f "delims=- tokens=1,2" %%i in (51.txt) do (
- @echo %%i>>52.txt
- @echo %%j>>52.txt
- )
- for /f "eol=-" %%i in ('find "6" 52.txt') do echo %%i>>53.txt
-
- for /f "delims=" %%i in (53.txt) do (
- if not defined %%i set %%i=A & echo %%i>>54.txt
- )
- del 50.txt 51.txt 52.txt 53.txt
- pause
复制代码
作者: apang 时间: 2012-7-31 10:44
试试代码一和代码二的最后加上endlocal语句
作者: 咒夜坠 时间: 2014-2-13 15:19
回复 2# apang
这个问题好像已经很久了
但是当时我是将后2个批处理合并在一起不好用
但是就像现在这样分开却可以正常使用
作者: DAIC 时间: 2014-2-13 16:50
- @echo off
- del 50.txt 51.txt 52.txt 50.txt 53.txt 54.txt 55.txt
- for /f "delims=: tokens=2" %%i in (原始记录.txt) do echo %%i>>50.txt
- for /f "delims=" %%i in (50.txt) do (
- if not defined 1_%%i (
- set 1_%%i=A
- echo %%i>>51.txt
- )
- )
-
- for /f "delims=- tokens=1,2" %%i in (51.txt) do (
- echo %%i>>52.txt
- echo %%j>>52.txt
- )
- for /f "eol=-" %%i in ('find "6" 52.txt') do echo %%i>>53.txt
-
- for /f "delims=" %%i in (53.txt) do (
- if not defined 2_%%i (
- set 2_%%i=A
- echo %%i>>54.txt
- )
- )
- del 50.txt 51.txt 52.txt 53.txt
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |