0

How can i get a word from a file and set it to a variabile for ex:

The text file contains bunch of text and i want to find only one word with the 4 or 5 random characters behind it

Fatbardh: 79%

Now i want to get that Fatbardh word but the 79% could be random number it can be any number, i want to get that random number and set it to an variable

can someone help me the text file is pretty long with a lot of words as well not only containing one word i dont know how to do it

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • What have you tried? Where are you stuck? Please read at least the entire [tour page](http://stackoverflow.com/tour) to learn how this site works! – aschipfl Oct 10 '16 at 06:23

1 Answers1

0

Since you know the string token in the line you're searching for, you can use FOR /F to process the output of the FINDSTR command.

@echo off
for /f "tokens=2 delims=: " %%a in ('findstr /i "Fatbardh" "YourFile.txt"') do set percent=%%a
echo %percent%

If you don't want the % symbol in the variable, include it in the delimiters.

@echo off
for /f "tokens=2 delims=:%% " %%a in ('findstr /i "Fatbardh" "YourFile.txt"') do set percent=%%a
echo %percent%
soja
  • 1,587
  • 8
  • 8
  • Here is a text file on the link below. Somewhere on that text file there is a "Mastery:" word without quotes close to that there is a percentage number that can be a random number, in this case it is 33% i want to get that percentage number and set it to a variabile I want to thank you for your answer =) https://drive.google.com/open?id=0B3FOapm5Vb56aXdNdmhmQkEtRXc – Fatbardh Stublla Oct 10 '16 at 17:46
  • You're dealing with markup. This might be a better answer: http://stackoverflow.com/questions/28893147/need-to-parse-out-string-from-html-document-in-a-batch-file – soja Oct 10 '16 at 22:42