在Windows命令行上使用findstr查找字符串的最后一次出现(Find last occurence of a string using findstr on windows command line)
我有一个带有字符串的文本文件出现多行。 我想得到这是字符串最后一次出现的行。 我可以使用下面的命令找到所有出现但我只希望在单行命令中出现最后一次。
findstr /C:"Apple Ball Cat" Book.txt如果有可能,有人可以指导我吗?
I have a text file with a string occurs multiple lines. I want to get the line where this is the last occurrence of the string. I could find all occurrences using below command but I want only last occurrence in single line command.
findstr /C:"Apple Ball Cat" Book.txtCan someone guide me if it is possible?
最满意答案
来自命令行的FOR命令 :
(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命令中(可能,假设) 使用双引号转义的cmd -poisonous字符 。
FOR command from command line:
(for /F "delims=" %G in ('findstr /C:"Apple Ball Cat" Book.txt') do @set "lastoccur=%G")&set lastoccurFrom a batch script:
@echo off set "lastoccur=" for /F "delims=" %%G in ('findstr /C:"Apple Ball Cat" Book.txt') do set "lastoccur=%%G" set lastoccur echo "%lastoccur%"In echo command are (possible, supposed) cmd-poisonous characters escaped using double quotes.
更多推荐
发布评论