Hopefully the following example will come close to meeting your requirements. Once you get it saved to your hard drive as "GetLine.bat", get into the same directory with it and type for brief instructions. A quick example of usage would be:- GetLine 28 c:\windows\system.ini
This would display (and store) a string containing the first six words from the 28th line of the file "c:\windows\system.ini".
Code:
@echo off
if (%2)==() goto Syntax
if (%2)==(?) goto Syntax
if (%2)==(/?) goto Syntax
if (%1)==() goto NoVarA
if not exist %2 goto NoFile
goto Begin
:Syntax
cls
echo.
echo Name: GetLine.bat - (For U.S.A.'s MS-DOS 5.nn/6.nn and Windows 95/98/Me).
echo.
echo Purpose: Display (and store) the first six words from the "nth" line in the
echo text file specified.
echo.
echo Syntax: GetLine ## [d:][\path\]filename
echo.
echo Where: "##" is the line number you want to see.
echo.
echo and: "[d:][\path\]filename" is the complete "drive:\path\filename.ext" of
echo the file you want to use. (Note: The "[d:]" (drive) and "[\path\]"
echo are optional. Whether you need either or both depends on the file's
echo location in relation to your current location.
echo.
echo Example: GetLine 28 c:\windows\system.ini
echo.
echo Would return a string containing the first six words from the 28th
echo line of the file "c:\windows\system.ini".
echo.
echo Requires: FIND.EXE (anywhere in the PATH) and enough room in the environment
echo to hold the length of: the line number (times two), the complete
echo filename as well as the line retrieved, plus 41 characters.
echo.
goto End
:Begin
for %%x in (File VarA VarB) do set %%x=
for %%x in (~ enter) do if exist %%x.bat del %%x.bat
set VarA=%1
set File=%2
:FindIt
type %File%|find /n /v "!@#"|find "[%VarA%]">~.bat
if errorlevel 1 goto NotFound
echo.>>~.bat
date<~.bat | find "Enter">~.bat
echo set VarB=%%4 %%5 %%6 %%7 %%8 %%9>enter.bat
for %%x in (call del) do %%x ~.bat
del enter.bat
:Display
echo.
echo File: %File%
echo VarA: %VarA%
echo VarB: %VarB%
echo.
set cmdline=
goto End
:NoFile
echo.
echo Error: File "%2" does not exist
echo.
goto End
:NoVarA
echo.
echo Error: You must specify a line number
echo.
goto End
:NotFound
echo.
echo Error: File "%File%" does not contain a line number "%VarA%"
echo.
:End
BTW, GetLine.bat sets three environment variables: "VARA" will contain the specified line number, "VARB" the returned six-word string and "FILE" the filename specified.