Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: first lines of a file using type  (Read 3017 times)

0 Members and 1 Guest are viewing this topic.

barak1812

  • Guest
first lines of a file using type
« 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
 ???

ghostdog74



    Specialist

    Thanked: 27
    Re: first lines of a file using type
    « Reply #1 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

    contrex

    • Guest
    Re: first lines of a file using type
    « Reply #2 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

    barak1812

    • Guest
    Re: first lines of a file using type
    « Reply #3 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