我想寫一個腳本。我使用xmlrpc的遠程過程調用來獲取URL。例如,我將輸出分配爲一個變量,如url=$(xmlrpc 192.168.1.1 command...)
。這是過程調用的輸出,當輸出到文件:提取多行變量中的單引號之間的文本與sed
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都將文件作爲參數,而不是字符串。 – 123
我沒有特別的原因使用sed。我也嘗試過awk和grep。沒想到嘗試本地shell。無論什麼作品。很高興知道,它不會以字符串作爲參數。謝謝。 – user2328273