Windows Batch: Grep text in first quotation marks

I've got a text file with following line:

17,60,"10 Ursae Majoris",0.03125,34.90625,-39.09375,0,0,176,None,5,None,64,Anarchy,10,None,,,,0,1678643440,1678643440,"10 Ursae Majoris",,,3,Common,2415659059555

and need to get the name inside the first quotation marks, so 10 Ursae Majoris the second quotation marks should be ignored.

my code can't work, as I'm on Windows Batch and not on linux:

echo off

for /f "delims=," %%i in (systems.txt) do echo %%i | grep -o '([^""]*)' | head -1

what is the Windows Batch equivalent? Many thanks.

searched and found Regex - Match only first instance of brackets

Upvotes: 0

Views: 65

Answers (1)

Aacini
Aacini

Reputation: 67206

This is my systems.txt test file:

17,60,"10 Ursae Majoris",0.03125,34.90625,-39.09375,0,0,176,None,5,None,64,Anarchy,10,None,,,,0,1678643440,1678643440,"10 Ursae Majoris",,,3,Common,2415659059555

This is my Batch code:

@echo off
setlocal
for /F "delims=" %%a in (systems.txt) do set "line=%%a"
set "line=%line:*"=%"
set "name=%line:"=" & rem "%"
echo %name%

This is the output:

10 Ursae Majoris

Upvotes: 0

Related Questions