从Objs.out文件中的第3行开始的内容取出存到0.txt中。
@echo off if exist Objs.out ( rem get lines from the 3rd line set n=1 SetLocal EnableDelayedExpansion for /f "delims=" %%i in (Objs.out) do ( echo %%i if !n! geq 3 ( echo %%i >> 0.txt ) else ( echo not matching... ) set /a n=!n!+1 ) ) else ( echo not found Objs.out )
for /f "skip=2 delims=" %%i in (objs.out) do ( ... )
if exist 0.txt ( for /f "tokens=1,2" %%i in (0.txt) do ( echo %%i echo %%j if %%j == T ( echo show table %%i; >> 1_DDL.txt ) else ( if %%j == V ( echo show view %%i; >> 1_DDL.txt ) ) ) ) else ( echo not found 0.txt )上述采用tokens获取的方法,在多数情况下很好用。考虑另外一种情况,若某一列中含有空格,则无法使用这种方法了。可采用2.2中的方法。
for /f "skip=2 delims=" %%i in (objs.out) do ( endlocal set ii=%%i SetLocal EnableDelayedExpansion echo !ii! rem echo !ii:~-1! if !ii:~-1! == T ( echo drop table hadoop."!ii:~0,30!"; >> drop.sql rem echo show stats values on hadoop."%%i"; >> drop.sql ) else ( if !ii:~-1! == V ( echo drop view hadoop."!ii:~0,30!"; >> drop.sql ) else ( if !ii:~-1! == O ( echo drop table hadoop."!ii:~0,30!"; >> drop.sql ) ) ) )