Computer Hope
Microsoft => Microsoft DOS => Topic started by: barak1812 on June 26, 2007, 02:42:39 AM
-
Hi,
I try to look for a way to look only for the first lines of a file.
Is it can be done using type or is there is another command?
TNX
???
-
can't remember who, but someone says this can do it.
set /p var=< filename
-
You could download one of the many DOS/WIN equivalents to the Unix HEAD command or you could save this batch file somewhere on your path
If you call it htype.bat the usage would be htype "filename.txt" N where N is the number of lines you want to see. Use quotes if the filename contains spaces. Use CALL if from a batch file.
@echo off
setlocal enabledelayedexpansion
set /a lin=1
set /a max=%2
for /f "delims=" %%L in (%1) do (
echo %%L
set /a lin+=1
if !lin! GTR %max% goto end
)
:end
-
You could download one of the many DOS/WIN equivalents to the Unix HEAD command or you could save this batch file somewhere on your path
If you call it htype.bat the usage would be htype "filename.txt" N where N is the number of lines you want to see. Use quotes if the filename contains spaces. Use CALL if from a batch file.
@echo off
setlocal enabledelayedexpansion
set /a lin=1
set /a max=%2
for /f "delims=" %%L in (%1) do (
echo %%L
set /a lin+=1
if !lin! GTR %max% goto end
)
:end
Tanks, it work beautiful, it as been a great help