回声从一个文本文件,其中“n”的第n行是一个命令行参数 [英] Echo the nth line from a text file where 'n' is a command line argument
本文介绍了回声从一个文本文件,其中“n”的第n行是一个命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有喜欢的数字简单的文本文件:
I have a simple text file with numbers like:
12345
45678
34567
89101
我需要一个批次将返回 N
日线从该文件。 N
应该从一个命令行参数服用。
I need a batch that will return the n
th line from this file. n
should be taken from a command line argument.
我很新批脚本等这提前为任何帮助感谢。
I am very new to batch scripting so Thanks in advance for any help on this.
推荐答案
要获得第n行的文件您可以使用更多+ N(对于一号线为n = 0)。结果
拆分文件的其余部分,你可以使用 FOR / F
循环。
这工作就算了,如果有第n行之前的空行。结果
这可能是必要的EOL设置为一个未使用的字符或换行(默认为;
)
This works even, if there are empty lines before the nth line.
It could be necessary to set the EOL to an unused character or to linefeed (default is ;
)
set "lineNr=%1"
set /a lineNr-=1
for /f "usebackq delims=" %%a in (`more +%lineNr% text.txt`) DO (
echo %%a
goto :leave
)
:leave
这篇关于回声从一个文本文件,其中“n”的第n行是一个命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文