Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何使用标准windows命令行从SQL文件中读取第一行_Batch File_Command Line - Fatal编程技术网

Batch file 如何使用标准windows命令行从SQL文件中读取第一行

Batch file 如何使用标准windows命令行从SQL文件中读取第一行,batch-file,command-line,Batch File,Command Line,是否可以在windows命令行中仅读取.sql文件的第一行 如果是这样的话,我该怎么做呢?谷歌还没有找到一个可行的解决方案 我只有标准的windows命令提示符这看起来像是这个问题的副本; 从那张票上引用被接受的答案 这里有一个通用批处理文件,用于打印GNUhead实用程序等文件中的顶部n行,而不仅仅是一行 @echo off if [%1] == [] goto usage if [%2] == [] goto usage call :print_head %1 %2 goto :eof

是否可以在windows命令行中仅读取.sql文件的第一行

如果是这样的话,我该怎么做呢?谷歌还没有找到一个可行的解决方案


我只有标准的windows命令提示符

这看起来像是这个问题的副本;

从那张票上引用被接受的答案

这里有一个通用批处理文件,用于打印GNU
head
实用程序等文件中的顶部
n
行,而不仅仅是一行

@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
例如:

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

它当前不计算空行数。它还受批处理文件行长度8 KB的限制。

仅读取(文本)文件的第一行:


什么类型的文件?一个.txt文件?@Karel janmissghers.sql,但是非常重要的是,这个代码可以放在一个批处理文件中,并且您可以在命令行中执行批处理文件。如示例所示。
<file.txt set /p line=
echo %line%