比赛后的模式

时间:2011-03-14 08:11:24

标签: sed

$string = "http://192.168.0.1/?url=http://www.google.com/?hl=";

如何仅返回

http://www.google.com/?hl=

使用linux命令

1 个答案:

答案 0 :(得分:3)

如果您的测试字符串确实位于名为string的shell变量中,那么它就像这样简单:

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

如果您真的打算使用 unix命令,那么我建议使用perlsed。 Perl的优点是能够使用非贪婪的限定符。

使用perl

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

使用sed

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