0

I want to write Batch script to search inside a txt file. I want to find out coordinated of a point. For example terminalpoint: (100, 255).

I know how to find out whether there is "terminalpoint" in text file. But I want to pick up the coordinates.

Please give me some example......

lankabeta
  • 91
  • 2
  • 7
  • 15
  • 2
    Do you searched this site? "[batch] How to read a file" – jeb Dec 08 '11 at 09:12
  • Yes I did....But I could not find any examples.....if you find please give me the link – lankabeta Dec 08 '11 at 09:36
  • 1
    Hmm, it's the second hit [batch script - read line by line](http://stackoverflow.com/questions/4527877/batch-script-read-line-by-line), then you only have to add your code into the `:processLine` function – jeb Dec 08 '11 at 10:01
  • Reading line by line is not problem to me.....But I need to take the coordinates. for example:terminalpoint: 100, 255 . I have to read next word OR value to terminalpoint: (if %a == "terminalpoint:") then read next value.....Is it possible... please help me – lankabeta Dec 08 '11 at 10:31
  • If that isn't the problem, you should edit your question, showing your code and where your problem is – jeb Dec 08 '11 at 10:35

1 Answers1

2

The FOR command below achieve this process: For each line in the text file that contains "terminalpoint" string, it show the FIRST text in the line enclosed in parentheses:

for /F "tokens=2 delims=()" %%a in ('findstr "terminalpoint" thefile.txt') do echo %%a

If you want to store both coordinates in two variables:

for /F "tokens=2 delims=()" %%a in ('findstr "terminalpoint" thefile.txt') do (
    for /F "tokens=1,2 delims=," %%x in ("%%a") do (
        set x=%%x
        set y=%%y
    )
)
Aacini
  • 65,180
  • 12
  • 72
  • 108