【发布时间】:2017-11-18 12:49:12
【问题描述】:
我正在尝试编写脚本。我使用带有 xmlrpc 的远程过程调用来获取 url。例如,我将输出分配为一个变量,例如url=$(xmlrpc 192.168.1.1 command...)。这是输出到文件时过程调用的输出:
Result:
String: 'http://example.url'
这一切都与echo $url 一起显示在一行中。当我尝试使用 sed s/^.*'\(.*\)'.*$/\1/ $url 提取单引号之间的 URL 时,我得到以下信息:
sed: can't read Result:: no such file or directory
sed: can't read String:: no such file or directory
sed: can't read http://example.url: no such file or directory
也许多行是问题所在。我收到grep -oP "(?<=').*?(?=')" $url 的类似错误有什么想法吗?我只想提取网址。
【问题讨论】:
-
为什么要“使用 sed”?例如,如果这是在 bash 中,您是否有理由不使用 shell 的本机正则表达式支持?
-
那是因为 sed 和 grep 都将文件作为参数,而不是字符串。
-
我使用 sed 没有特别的原因。我也试过 awk 和 grep。没想到尝试原生shell。什么都行。很高兴知道,它不接受字符串作为参数。谢谢。