Often need to read specified lines of files, so I wrote a small program segment (ReadLine.Bat) to read specified lines of files for future calls.
It is also relatively simple to use: "Call ReadLine <file name> <number of lines to skip> <number of lines to read>" can be used. For example, adding a sentence "Call ReadLine a.txt 5 7" in a batch file, then it will skip the first 5 lines of the a.txt file and display the following 7 lines of characters, including blank lines. You can also not specify the third parameter.
ReadLine.Bat
@echo off&SetLocal ENABLEDELAYEDEXPANSION
if "%1"=="" (goto --help) else (set file=%~s1)
if "%2"=="" (set first="delims=: tokens=1*") else (set first="skip=%2 delims=: tokens=1*")
if "%3"=="" (
for /f %first% %%a in ('findstr /n .* %file%') do echo/%%b
goto :EOF
)
set last=%3
set loop=0
for /f %first% %%a in ('findstr/n .* %file%') do (
if not defined lxmxn (echo/%%b&set /a loop+=1) else (goto :EOF)
if "!loop!"=="%last%" set lxmxn=Nothing
)
GOTO :EOF
:--help
echo/======================================
echo/This program segment needs to be run with parameters
echo/&echo/Usage:&echo/Call ReadLine ^<file name^> ^<number of lines to skip^> ^<number of lines to read^>
echo/&echo/For example: call ReadLine aa.txt 5 7, which will skip the first 5 lines of the aa.txt file and read the following 7 lines of characters
echo/&echo/If ^<number of lines to skip^> is not specified, it will read from the first line of the file
echo/&echo/When specifying ^<number of lines to read^>, ^<number of lines to skip^> must be specified
echo/======================================
goto :eof
Recent Ratings for This Post
( 3 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| baomaboy | +3 | 2007-03-19 05:28 |
| electronixtar | +11 | 2007-03-19 23:37 |
| kcdsw | +4 | 2007-07-09 18:16 |

