Windows batch command(s) to read first line from text file
uh? imo this is much simpler
set /p texte=< file.txt
echo %texte%
Here's a general-purpose batch file to print the top n
lines from a file like the GNU head
utility, instead of just a single line.
@echo off
if [%1] == [] goto usage
if [%2] == [] goto usage
call :print_head %1 %2
goto :eof
REM
REM print_head
REM Prints the first non-blank %1 lines in the file %2.
REM
:print_head
setlocal EnableDelayedExpansion
set /a counter=0
for /f ^"usebackq^ eol^=^
^ delims^=^" %%a in (%2) do (
if "!counter!"=="%1" goto :eof
echo %%a
set /a counter+=1
)
goto :eof
:usage
echo Usage: head.bat COUNT FILENAME
For example:
Z:\>head 1 "test file.c"
; this is line 1
Z:\>head 3 "test file.c"
; this is line 1
this is line 2
line 3 right here
It does not currently count blank lines. It is also subject to the batch-file line-length restriction of 8 KB.
Uh you guys...
C:\>findstr /n . c:\boot.ini | findstr ^1:
1:[boot loader]
C:\>findstr /n . c:\boot.ini | findstr ^3:
3:default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
C:\>