My Tortoise SVN SVN update command generally returns me this output:

C:\proj>svn update
Updating '.':
A 'some-file1.txt'
D 'some-file2.txt'
Restored 'some-file3.txt'
U 'some'file4.txt'
C 'some file5.txt' B
At revision 123.

Please note that except for the first line (always starting with Updating) and last line (always starting with At), each line will always have:

  • an action in the first column. This can be a letter or a word
  • a file in the second column, wrapped in single quotes. Unfortunately filenames can contain single quotes or whitespaces within them!
  • possibly more columns with single letters in them. But I don't care about them.

In a batch file that I am writing, I need to have the actions and files. The actions I manage to get, but the files are too tricky for me it seems. Technically, all I want is everything between the first single quote and the last single quote on the line.

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('"svn update"') DO (
    set line=%%a
    for /f "tokens=1" %%b in ("!line!") do (
        set action=%%b
        if "!action!" neq "Updating" (
            if "!action!" neq "At" (
                set file= >>> I DON'T KNOW WHAT TO DO HERE <<<
                echo We did !action! to !file!

Once this batch file is working correctly, it should output:

We did A on some-file1.txt
We did D on some-file2.txt
We did Restored on some-file1.txt
We did U on some'file1.txt
We did C on some file1.txt
  • Does it have to be bat, or can it be vbscript or even awk? It seems like the requirement is to extract field 1 and field 2 from an output file, but the challenge is the definition of field, for field 2 specifically. It's not space terminated. It's not wrapped in quotes. I don't think you can make a precise enough definition for field 2 - how would you handle "C 'some 'file5.txt' B" for example - whatever definition you use for this example is wrong. Oct 22, 2018 at 16:48
  • To add a proposed approach - if there are no quotes possible after field 2, then define field two as "everything from the first quote in the line searching forwards, to everything in the last quote in the line searching backwards"? I can imagine doing that pretty easily in vbscript, perl or awk, but not in bat. Oct 22, 2018 at 16:51

1 Answer 1


I seem to have found a solution with powershell, by replacing the set file= line with the following

for /f "delims=" %%c in ('"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -Command ""$Env:line -replace '^^[^^'']*''' -replace '''[^^'']*$'"" "') DO (
    set file=%%c

Powershell takes the %line% (there it is called $Env:line), and replaces ^[^']*' with nothing, and replaces '[^']*$ with nothing, and returns the string which is then caught with for /f again and put into %file%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.