Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you mean the Windows <code>cmd</code> interpreter (I'd be surprised if you really <em>were</em> still using DOS), the following script will do what you want:</p> <pre><code>@echo off setlocal enableextensions enabledelayedexpansion set first=1 for /f "delims=" %%i in (infile.txt) do ( if !first!==1 echo %%i set first=0 ) endlocal </code></pre> <p>With an input file of <code>infile.txt</code> as:</p> <pre><code>line 1 line 2 line 3 </code></pre> <p>this will output:</p> <pre><code>line 1 </code></pre> <p>This will still <em>process</em> all the lines, it just won't print those beyond line 1. If you want to actually stop processing, use something like:</p> <pre><code>@echo off setlocal enableextensions enabledelayedexpansion for /f "delims=" %%i in (infile.txt) do ( echo %%i goto :endfor ) :endfor endlocal </code></pre> <p>Or you could just go get your hands on <a href="http://www.cygwin.com/" rel="noreferrer">Cygwin</a> or <a href="http://gnuwin32.sourceforge.net/" rel="noreferrer">GnuWin32</a> and use the <code>head</code> program. That's what I'd do. But, if that's not an option (some workplaces don't allow it), you can create a similar cmd file in Windows itself as follows (<code>winhead.cmd</code>):</p> <pre><code>@echo off setlocal enableextensions enabledelayedexpansion if x%1x==xx goto :usage if x%2x==xx goto :usage set /a "linenum = 0" for /f "usebackq delims=" %%i in (%1) do ( if !linenum! geq %2 goto :break1 echo %%i set /a "linenum = linenum + 1" ) :break1 endlocal goto :finish :usage echo.winhead ^&lt;file^&gt; ^&lt;numlines^&gt; echo. ^&lt;file^&gt; echo. is the file to process echo. (surround with double quotes if it contains spaces). echo. ^&lt;numlines^&gt; echo. is the number of lines to print from file start. goto :finish :finish endlocal </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload