Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find the default gateway in a openvpn scenario where the route output looks like that:

IPv4 Route Table
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric

So I googled around a bit and a found this script here:

@For /f "tokens=3" %%* in (
   'route.exe print ^|findstr "\<\>"'
   ) Do @Set "DefaultGateway=%%*"

echo %DefaultGateway%

This works, but matches both lines in the route output.

But I need to find this line:     10

So I tried to modify the findstr parameter like this:

findstr "\<\>.\<\>"

in the expectation that '.' will match for the tab between the columns. But it doesn't. It will still set DefaultGateway to

I couldn't find a clue in MS documentation either. Maybe someone knows the right expression? Thanks a lot.

share|improve this question
up vote 1 down vote accepted

Try this:

For /f "tokens=3" %%* in (
   'route print ^|findstr "\<*\>"'
   ) Do @Set "DefaultGateway=%%*"

echo %DefaultGateway%

And you can check findstr /? for more informations.

share|improve this answer
Ah thats perfect :-) But I do not understand why. When I wrote "\<\>.\<\>" did it make findstr stop looking after the first '\>' ? – user4711 Oct 5 '12 at 9:16
First of all the . won't do alone, cause aparently it's not just a single tab in the middle. Then to be honest, I'm not really sure how the \< and \> work, it's not really part of the standard implementation of regexs as I know it... It's supposedly "beginning/end of word". So I just played around with it until it worked ;P – m4573r Oct 5 '12 at 9:19
Quite likely the \< and \> forms are required simply to escape the DOS redirection operators. – Karan Oct 7 '12 at 17:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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