Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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 批处理:在txt文件中搜索一个单词,并返回看到它的最后一行号_Batch File_Search_For Loop_Numbers_Line - Fatal编程技术网

Batch file 批处理:在txt文件中搜索一个单词,并返回看到它的最后一行号

Batch file 批处理:在txt文件中搜索一个单词,并返回看到它的最后一行号,batch-file,search,for-loop,numbers,line,Batch File,Search,For Loop,Numbers,Line,我有一个txt文件中的项目列表,其中某些单词被写了几次。我做了一个批处理文件,搜索此文本并返回指定单词所在的行号。然而,它只给出了第一次看到的数字,但我希望相反,我希望它返回到最后一次看到的地方 以下是我在list.txt中的列表: Marcel Maurice Melane Bob Melane 这个脚本返回我“3”,而我只想要“5”: 有什么想法吗?非常感谢,非常感谢 < p>移除 /x,使用 FordSTR/I/N MELANE“%TrraseFruts%”这实际上是一个围绕“代码> .

我有一个txt文件中的项目列表,其中某些单词被写了几次。我做了一个批处理文件,搜索此文本并返回指定单词所在的行号。然而,它只给出了第一次看到的数字,但我希望相反,我希望它返回到最后一次看到的地方

以下是我在list.txt中的列表:

Marcel
Maurice
Melane
Bob
Melane
这个脚本返回我“3”,而我只想要“5”:


有什么想法吗?非常感谢,非常感谢

< p>移除<代码> /x<代码>,使用<代码> FordSTR/I/N MELANE“%TrraseFruts%”

这实际上是一个围绕“代码> .FunSTR< <代码>的bug的工作,它不考虑最后一行A(精确)匹配使用<代码> /x<代码>开关,除非它以新的行终止;如果没有
/X
,则最终的新行没有差异;但是,
/X
指定整行必须匹配,因此不声明开关会使包含搜索字符串的每一行都被视为匹配,因此批处理脚本的固有功能已更改@tref应该指定需要什么。
set "textfile=C:SomewhereInMyPC\List.txt"
for /F %SKIP% "delims=:" %%N in ('findstr /i /x /n Melane "%textfile%"') do set line=%%N
echo %line%
pause