Solved How to find last specific string in a file?

July 21, 2011 at 04:17:59
Specs: Windows XP
How to find last specific string in a file? For example: I have a text file myfile.txt containing multiple string "SYSTEM OVERVIEW" I want to find the line of the last of that string "SYSTEM OVERVIEW". Can someone help me with these. Thnx in advance..

See More: How to find last specific string in a file?

Report •


✔ Best Answer
September 19, 2011 at 09:49:50
It's designed to be a part of a script, not a standalone script. If you wanted to make it standalone, you'd probably do something like this:
for /f "delims=" %%a in ('findstr /c:"SYSTEM OVERVIEW" myfile.txt') do @set line=%%a
@echo %line%

How To Ask Questions The Smart Way



#1
July 21, 2011 at 20:18:51
Test this:

@echo off
cls
setlocal


for /f "tokens=*" %%1 in (%temp%\trial.txt) do (
    echo %%1 | find "SYSTEM OVERVIEW">nul&&set line=%%1
    )
echo %line%


Please come back & tell us if your problem is resolved.


Report •

#2
September 16, 2011 at 07:35:14
this one didn't work.. Can someone help me on here..

Report •

#3
September 16, 2011 at 07:55:52

Report •

Related Solutions

#4
September 16, 2011 at 11:01:05
try findstr

Report •

#5
September 17, 2011 at 07:02:14
The response is "the syntax of the command is incorrect."

Report •

#6
September 17, 2011 at 07:21:40
The more information you provide, the greater the chance someone will help you. Case in point:
for /f "delims=" %%a in ('findstr /c:"SYSTEM OVERVIEW" myfile.txt') do set line=%%a

How To Ask Questions The Smart Way


Report •

#7
September 17, 2011 at 10:17:33
OK. In my txt file "myfile.txt" there's a lot of string "SYSTEM OVERVIEW" with different values next to it..Ex of the file. SYSTEM OVERVIEW - 12345 ,
SYSTEM OVERVIEW - ABCDE , SYSTEM OVERVIEW - XXXXX. I want to find or echo only the last SYSTEM OVERVIEW which is XXXXX....i want the output to be SYSTEM OVERVIEW - XXXXX .
the last one u suggest is showing all the SYSTEM OVERVIEW values..
Thnx again in advance.

Report •

#8
September 19, 2011 at 05:17:22
This looks similar to what you need...

http://stackoverflow.com/questions/...


Report •

#9
September 19, 2011 at 09:49:50
✔ Best Answer
It's designed to be a part of a script, not a standalone script. If you wanted to make it standalone, you'd probably do something like this:
for /f "delims=" %%a in ('findstr /c:"SYSTEM OVERVIEW" myfile.txt') do @set line=%%a
@echo %line%

How To Ask Questions The Smart Way


Report •

#10
September 22, 2011 at 20:21:12
Thnx Razor2.3 it works.. But how can i do these in a multiple files? Ex. I have myfile1.txt, myfile2.txt and myfile3.txt.. I tried the command by just putting (myfile*)
but only the myfile3.txt echoed the last line of SYSTEM OVERVIEW...Thnx in advance..

Report •

#11
September 23, 2011 at 05:39:41
Assuming you wan the last "SYSTEM OVERVIEW" line among all the files, that gets more complicated than I'd normally get with a batch file. If you want the last "SYSTEM OVERVIEW" line in each file, that'd require nesting FOR loops.

How To Ask Questions The Smart Way


Report •


Ask Question