Reputation: 416
How can I shorten output of this command.
nslookup myip.opendns.com resolver1.opendns.com > %~d0\bat\setup\ipaut\myip.txt
This gives me a text file:
Server: resolver1.opendns.com
Address: 208.67.222.222
Name: myip.opendns.com
Address: 84.48.190.45
What I actually want in the text file is the myip.opendns.com address. Example
84.48.190.45
Upvotes: 0
Views: 531
Reputation: 67216
@echo off
setlocal EnableDelayedExpansion
set "var="
for /F "tokens=2 delims=: " %%a in ('nslookup myip.opendns.com resolver1.opendns.com') do (
if not defined var (
set "var=%%a"
) else (
set "!var!=%%a"
set "var="
)
)
echo %myip.opendns.com%> output.txt
Upvotes: 2
Reputation: 14290
FOR /F "tokens=2 delims=: " %%G in ('nslookup myip.opendns.com resolver1.opendns.com') do >myip.txt echo %%G
This parses the output of the nslookup command and outputs the result to a text file.
Upvotes: 1