【问题标题】:Extract the IP address and port number from a environment variable using windows batch command使用 windows 批处理命令从环境变量中提取 IP 地址和端口号
【发布时间】:2017-07-07 18:17:55
【问题描述】:

我在 Windows 中有一个 environment variable,它有一个 value,如下所示

"https://xx.xx.xx.xx:yyyy/xxxx        (login: xxx, password: xxxxx)"

我的任务是从环境变量extract the IP address and port number。我能够在 Linux 环境中做到这一点。命令如下

echo "$env_variable" | cut -d '/' -f 3 | cut -d ':' -f 1 - for the IP Address
echo "$env_variable" | cut -d '/' -f 3 | cut -d ':' -f 2 - for the port number

有人可以帮我在 Windows 系统上使用 windows batch command 做同样的事情吗?

编辑

这里xx.xx.xx.xx是IP地址,yyyy是端口号。

【问题讨论】:

  • 我宁愿把数据放在更好的格式,例如多个变量,它们毕竟是为了方便机器使用,而不是为用户提供漂亮的打印信息

标签: linux windows parsing batch-file


【解决方案1】:
@echo off
set var="https://xx.xx.xx.xx:yyyy/xxxx        (login: xxx, password: xxxxx)"
for /f "tokens=2,3 delims=/:" %%a in (%var%) do (
   set ip=%%a
   set port=%%b
)
echo %ip%, %port%

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    相关资源
    最近更新 更多