test_1.bat- @echo off
- REM 读取哪个文件
- set "SrcFile=C:\Test\1.txt"
- REM 获取第几行
- set "DstRow=2"
- setlocal enabledelayedexpansion
- for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%SrcFile%"') do (
- set /a "CurRow+=1"
- if !CurRow! equ %DstRow% (
- echo,%%j
- goto :End
- )
- )
-
- :End
- pause
复制代码 test_2.bat- @echo off
- REM 读取哪个文件
- set "SrcFile=C:\Test\1.txt"
- REM 获取第几行
- set "DstRow=2"
- set "CurRow=0"
- for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%SrcFile%"') do (
- if %%i equ %DstRow% (
- echo,%%j
- goto :End
- )
- )
-
- :End
- pause
复制代码 test_3.bat- @echo off
- REM 读取哪个文件
- set "SrcFile=C:\Test\1.txt"
- REM 获取第几行
- set "DstRow=2"
-
- if %DstRow% equ 1 (
- set /p str=<"%SrcFile%"
- call echo,%%str%%
- goto :End
- )
- set /a "IgnoreCount=DstRow-1"
- call :GetRow %%IgnoreCount%%
- goto :eof
-
- :GetRow
- for /f "skip=%1 delims=" %%i in ('type "%SrcFile%"') do (
- echo,%%i
- goto :End
- )
-
- :End
- pause
复制代码
|