lankabeta
lankabeta

Reputation: 91

Search inside a txt file using batch script windows 7

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

Upvotes: 0

Views: 2863

Answers (1)

Aacini
Aacini

Reputation: 67216

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

Upvotes: 2

Related Questions