Sed 赛后模式

Sed 赛后模式,sed,Sed,如何只返回 $string = "http://192.168.0.1/?url=http://www.google.com/?hl="; 通过使用linux命令如果您的测试字符串确实位于名为string的shell变量中,那么它就很简单: http://www.google.com/?hl= 如果您真的打算使用unix命令,那么我建议您选择perl或sed。Perl的优点是能够使用非贪婪限定符 使用perl 使用sed 我投票支持你,因为我喜欢你的问题。有很多符号lol。 $ string

如何只返回

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

通过使用linux命令

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

http://www.google.com/?hl=
如果您真的打算使用unix命令,那么我建议您选择
perl
sed
。Perl的优点是能够使用非贪婪限定符

使用
perl
使用
sed

我投票支持你,因为我喜欢你的问题。有很多符号lol。
$ string="http://192.168.0.1/?url=http://www.google.com/?hl="
$ echo ${string#*=}
http://www.google.com/?hl=
$ echo "http://192.168.0.1/?url=http://www.google.com/?hl=" | perl -pe 's/.*?=//'
http://www.google.com/?hl=
$ echo "http://192.168.0.1/?url=http://www.google.com/?hl=" | sed 's/[^=]*=//'
http://www.google.com/?hl=