这样用 SED 还不如用批处理 同样的不通用
修正最后字符为“)”的话不能取到集数问题
- @echo off&setlocal enabledelayedexpansion
- for /l %%i in (0 1 9) do set "_%%i=%%i"
- for /f "usebackq delims=" %%i in ("a.txt") do (
- set var=%%i
- for /f "tokens=1*" %%a in ("%%i") do (
- if "%%b" neq "" (
- set str=%%b&call:lp
- if not "!e!"=="" for %%e in (!e!) do set var=!var:*%%e=!
- )
- if "!var!"=="%%i" (echo !var! !e!)else echo %%i
- set e=
- ))
- pause&exit
- :lp
- if defined str (
- set v=!str:~,1!
- if defined e (
- set e1=!str:~1!
- if defined _!v! (set e=!e!!v!) else (
- if "!v!"==")" if defined e1 set "e="&goto lp
- if "!v!"=="/" (
- if !e! gtr !e1! set e=!e:~1!
- )
- set e=第!e!集&exit/b)
- ) else if defined _!v! set e=!v!
- set str=!str:~1!
- goto lp
- )
- if not "!e!"=="" set e=第!e!集
复制代码
[ 本帖最后由 terse 于 2009-6-16 09:03 编辑 ] |