在Windows命令行上使用findstr查找字符串的最后一次出现(Find last occurence of a string using findstr on windows command l

编程入门 行业动态 更新时间:2024-10-27 07:18:20
在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.txt

Can 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 lastoccur

From 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.

更多推荐

本文发布于:2023-08-03 16:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1395164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   命令行   Find   Windows   findstr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!