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......

5
  • 2
    Do you searched this site? "[batch] How to read a file" Commented Dec 8, 2011 at 9:12
  • Yes I did....But I could not find any examples.....if you find please give me the link Commented Dec 8, 2011 at 9:36
  • 1
    Hmm, it's the second hit batch script - read line by line, then you only have to add your code into the :processLine function Commented Dec 8, 2011 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 Commented Dec 8, 2011 at 10:31
  • If that isn't the problem, you should edit your question, showing your code and where your problem is Commented Dec 8, 2011 at 10:35

1 Answer 1

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
    )
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.