Solved Extract one number from a specific line from a .txt file

November 19, 2015 at 02:56:45
Specs: Windows Server 2008 R2
Hello.

I have the following Problem with my batch-file:

findstr "Complete:" %MyLogFile% | findstr %ScanID% >>temp.txt
With the above findstr I'm able to extract the exact line of the .txt- file I need.

Now I need a number, which is in that line, so I thought about a pipe like this:
findstr "Complete:" %MyLogFile% | findstr %ScanID% | for /f "tokens=6" %%G IN (%MyLogFile%) DO @echo %%G >>temp.txt

But this gives me the numbers of all the lines in the entire file.

What can I do to only get the one from the line I chose?

Any help would be greatly appreciated, I'm at my wit's end...

message edited by Salander


See More: Extract one number from a specific line from a .txt file

Report •

#1
November 19, 2015 at 07:26:50
✔ Best Answer
for /F "tokens=6" %%G in ('findstr "Complete:" %MyLogFile% ^| findstr %ScanID%') do (@echo.%%G)  >> temp.txt


Report •

#2
November 19, 2015 at 20:35:01
A sample of your "Mylogfile", and sample of ScanId target value would be most helpful. (Substitute random stuff for actual values - the basic format is all that's needed.)

Report •

#3
November 20, 2015 at 05:21:34
It works now, thanks for the help!

Report •
Related Solutions


Ask Question