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 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.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments