Is there a split
command in Windows, to split command output? My command is:
ipconfig | findstr /i "Default gateway" | findstr [0-9]
and the output is:
Default Gateway...: x.x.x.x
I need a single command, and the output should be only x.x.x.x
.
On my computer, there are two gateways returned, one for IPv4 and one for IPv6. The
findstr
doesn't distinguish between them. However, for me IPv4 is returned before IPv6. This batch file extracts the IP address for the gateway from thefindstr
output:I split it into two separate
for
commands (instead of nesting thefor
commands) so that I could just grab the first 'gateway' returned from thefindstr
. The result has a leading space, so the 2ndfor
command removes the leading space. The& set yourvar=%_ip%
at the end is how you pass alocal
variable outside of thelocal
block, but you don't have to use that...there is not exactly a split function, but you can use
FOR
to accomplish what you want :