Computer Hope

Microsoft => Microsoft DOS => Topic started by: barak1812 on June 26, 2007, 02:42:39 AM

Title: first lines of a file using type
Post 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
 ???
Title: Re: first lines of a file using type
Post by: ghostdog74 on June 26, 2007, 02:50:21 AM
can't remember who, but someone says this can do it.
Code: [Select]
set /p var=< filename
Title: Re: first lines of a file using type
Post by: contrex on June 26, 2007, 04:23:42 AM
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.

Code: [Select]
@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
Title: Re: first lines of a file using type
Post by: barak1812 on June 26, 2007, 05:36:09 AM
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.

Code: [Select]
@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