-1

Is it possible to read just the first line from a .sql file in the windows command line?

If so, how can I do this - googleing has not come up with a solution that works.

All I have is standard windows command prompt

Alex
  • 3,730
  • 9
  • 43
  • 94

2 Answers2

1

This looks like a copy of this question; Windows batch command(s) to read first line from text file

Quoting the accepted answer from that ticket;

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.

0

To read just the first line of a (text) file:

<file.txt set /p line=
echo %line% 

This is the easiest solution. Dependent on the content (poison chars), echo might fail.

Stephan
  • 53,940
  • 10
  • 58
  • 91