Board logo

标题: 求助 根据下一行提取上一行的字符串 [打印本页]

作者: newswan     时间: 2010-6-20 23:56    标题: 求助 根据下一行提取上一行的字符串

mountvol的输出格式如下:
------------------------------begin--------------------------------
当前装入点的 VolumeName 可能值为:
    \\?\Volume{61260a4f-694f-11df-9198-806e6f6e6963}\
        C:\

    \\?\Volume{61260a52-694f-11df-9198-806e6f6e6963}\
        *** 无装入点 ***
------------------------------end--------------------------------

怎样根据
"C”或"***"
获得该行上面一行的值
\\?\Volume{.............................................................}\
作者: gool123456     时间: 2010-6-21 01:52

@echo off
for /f "delims=" %%i in (1.txt) do (
call :Mackt "%%i"
call :Mackt "" "%%i"
)
pause
exit
:Mackt
echo.%~1|findstr "\<C" 2>nul&& echo.%string%
echo.%~1|findstr "\<无装" 2>nul&& echo.%string%
set string=%~2
*是特殊字符
作者: gool123456     时间: 2010-6-21 02:11
再加个判断会快很多:
@echo off
for /f "delims=" %%i in (1.txt) do (
call :Mackt "%%i"
call :Mackt "" "%%i"
)
pause
exit
:Mackt
if not %1=="" (
echo.%~1|findstr "\<C" 2>nul&& echo.%string%
echo.%~1|findstr "\<无装" 2>nul&& echo.%string%
)
set string=%~2
[ Last edited by gool123456 on 2010-6-21 at 02:16 ]
作者: newswan     时间: 2010-6-21 03:03
收到。谢谢。。
作者: Hanyeguxing     时间: 2010-6-21 12:31

@echo off&setlocal enabledelayedexpansion
for /f %%a in (1.txt) do (if defined a echo.!b!&set a=
echo.%%a|findstr /i "c: ***">nul&&set a==||set b=%%a)
pause

作者: genteman     时间: 2010-6-21 14:46
[quote]Originally posted by Hanyeguxing at 2010-6-21 12:31 PM:
@echo off&setlocal enabledelayedexpansion
for /f %%a in (1.txt) do (if defined a echo.!b!&set a=
echo.%%a|findstr /i "c: ***">nul&&set a==||set b=%%a)
pause[/c ... [/quote]

这段代码虽然很精简,但是最后一次匹配的行却打印不出来,需要做些改进。



[code]@echo off & setlocal enabledelayedexpansion
for /f %%a in (1.txt) do (
echo.%%a|findstr /i "c: ***">nul&&echo.!b!
set b=%%a
)
[ Last edited by genteman on 2010-6-21 at 14:49 ]