开发者

pattern after match

开发者 https://www.devze.com 2023-02-17 03:01 出处:网络
$string = \"http://192.168.0.1/?url=http://www.google.com/?hl=\"; how to return only htt开发者_开发技巧p://www.google.com/?hl=
$string = "http://192.168.0.1/?url=http://www.google.com/?hl=";

how to return only

htt开发者_开发技巧p://www.google.com/?hl=

by use linux command


If your test string is truly in a shell variable named string then its as easy as this:

$ string="http://192.168.0.1/?url=http://www.google.com/?hl="
$ echo ${string#*=}
http://www.google.com/?hl=

If you really intend to use a unix command then I would suggest either perl or sed. Perl has the advantage of being able to use the non-greedy qualifier.

With perl

$ echo "http://192.168.0.1/?url=http://www.google.com/?hl=" | perl -pe 's/.*?=//'
http://www.google.com/?hl=

With sed

$ echo "http://192.168.0.1/?url=http://www.google.com/?hl=" | sed 's/[^=]*=//'
http://www.google.com/?hl=
0

精彩评论

暂无评论...
验证码 换一张
取 消