在windows命令行上使用findstr查找最后出现的字符串

在windows命令行上使用findstr查找最后出现的字符串,windows,command-line,Windows,Command Line,我有一个包含多行字符串的文本文件。我想得到这是字符串最后一次出现的行。我可以使用下面的命令找到所有引用,但我只希望在单行命令中找到最后一个引用 findstr /C:"Apple Ball Cat" Book.txt 如果可能的话,有人可以指导我吗?从命令行: (for /F "delims=" %G in ('findstr /C:"Apple Ball Cat" Book.txt') do @set "lastoccur=%G")&set lastoccur 从批处理脚本: @e

我有一个包含多行字符串的文本文件。我想得到这是字符串最后一次出现的行。我可以使用下面的命令找到所有引用,但我只希望在单行命令中找到最后一个引用

findstr /C:"Apple Ball Cat" Book.txt
如果可能的话,有人可以指导我吗?

从命令行:

(for /F "delims=" %G in ('findstr /C:"Apple Ball Cat" Book.txt') do @set "lastoccur=%G")&set lastoccur
从批处理脚本:

@echo off
set "lastoccur="
for /F "delims=" %%G in ('findstr /C:"Apple Ball Cat" Book.txt') do set "lastoccur=%%G"
set lastoccur
echo "%lastoccur%"
echo
中,命令是(可能的,假定的)。

来自命令行:

(for /F "delims=" %G in ('findstr /C:"Apple Ball Cat" Book.txt') do @set "lastoccur=%G")&set lastoccur
从批处理脚本:

@echo off
set "lastoccur="
for /F "delims=" %%G in ('findstr /C:"Apple Ball Cat" Book.txt') do set "lastoccur=%%G"
set lastoccur
echo "%lastoccur%"
echo
中,命令是(可能的,假定的)