Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract text between single quotes in mult line variable with sed

I am trying to write a script. I use a remote procedure call with xmlrpc to get a url. I assign the output as a variable all in one command like url=$(xmlrpc 192.168.1.1 command...) for example. This is the output of the procedure call when output to a file:

Result:

String: 'http://example.url'

It all shows up on one line with echo $url. When I try to extract the URL between the single quotes with sed s/^.*'\(.*\)'.*$/\1/ $url I get the following:

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

Maybe the multiple lines is the problem. I get a similar error with grep -oP "(?<=').*?(?=')" $url Any ideas? I just want to extract the URL.

like image 473
user2328273 Avatar asked Dec 09 '25 10:12

user2328273


1 Answers

sed -n "s/^.*'\(.*\)'.*$/\1/ p" <<< ${url}
like image 98
ArturFH Avatar answered Dec 10 '25 23:12

ArturFH