Find last occurence of a string using findstr on windows command line

Nagarjun

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?

JosefZ

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

find last occurence of multiple characters in a string in Python

From Dev

Find last occurence of string in multiple files

From Dev

PHP: Find last occurence of string in array

From Dev

Python: Using regex to find the last pair of occurence

From Dev

Python: Using regex to find the last pair of occurence

From Dev

find the last occurence of characters using javascript

From Dev

How do you find the last occurence of a pattern using string.find?

From Dev

ColdFusion - Last Occurence of a string using RefindNoCase

From Dev

Finding last occurence of string

From Dev

Finding last occurence of string

From Dev

PHP Replace Last Occurence of a Word in a Multi-Line String

From Dev

How to close last tab in firefox using windows command line

From Dev

How can I check (and delete) if the last line (that contains the last occurence of a string) has a comma as last character?

From Dev

Using SSH, search a file for a string and return the value next to it in the last occurence

From Dev

Windows 'findstr' command: Exclude results containing particular string

From Dev

Windows 'findstr' command: Exclude results containing particular string

From Dev

Python find last occurence in a file

From Dev

Python find last occurence in a file

From Dev

Using 'find' in the command line

From Dev

RegEx to match last occurence of a string

From Dev

Find files on Windows modified after a given date using the command line

From Dev

How to run regex find and replace using windows command line

From Dev

Remove certain characters in a string using Windows command line

From Dev

sql server find out first occurence and last occurence and replace them

From Dev

FINDSTR to find text at end of string

From Dev

Find string which include "%" with findstr

From Dev

Findstr find string and print out

From Dev

Powershell: Replace last occurence of a line in a file

From Dev

Find Index of Last Occurence in Multidimensional Array

Related Related

  1. 1

    find last occurence of multiple characters in a string in Python

  2. 2

    Find last occurence of string in multiple files

  3. 3

    PHP: Find last occurence of string in array

  4. 4

    Python: Using regex to find the last pair of occurence

  5. 5

    Python: Using regex to find the last pair of occurence

  6. 6

    find the last occurence of characters using javascript

  7. 7

    How do you find the last occurence of a pattern using string.find?

  8. 8

    ColdFusion - Last Occurence of a string using RefindNoCase

  9. 9

    Finding last occurence of string

  10. 10

    Finding last occurence of string

  11. 11

    PHP Replace Last Occurence of a Word in a Multi-Line String

  12. 12

    How to close last tab in firefox using windows command line

  13. 13

    How can I check (and delete) if the last line (that contains the last occurence of a string) has a comma as last character?

  14. 14

    Using SSH, search a file for a string and return the value next to it in the last occurence

  15. 15

    Windows 'findstr' command: Exclude results containing particular string

  16. 16

    Windows 'findstr' command: Exclude results containing particular string

  17. 17

    Python find last occurence in a file

  18. 18

    Python find last occurence in a file

  19. 19

    Using 'find' in the command line

  20. 20

    RegEx to match last occurence of a string

  21. 21

    Find files on Windows modified after a given date using the command line

  22. 22

    How to run regex find and replace using windows command line

  23. 23

    Remove certain characters in a string using Windows command line

  24. 24

    sql server find out first occurence and last occurence and replace them

  25. 25

    FINDSTR to find text at end of string

  26. 26

    Find string which include "%" with findstr

  27. 27

    Findstr find string and print out

  28. 28

    Powershell: Replace last occurence of a line in a file

  29. 29

    Find Index of Last Occurence in Multidimensional Array

HotTag

Archive