Shell脚本只从一行中提取IP地址

时间:2014-01-28 10:56:31

标签: shell scripting

使用bash脚本我想从以下

中仅提取IP地址

代理列表=“101.21.60.111:4666,101.21.60.112:4666

1 个答案:

答案 0 :(得分:1)

使用egrep -o

> s='proxy-list="101.21.60.111:4666,101.21.60.112:4666"'
> egrep -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' <<< "$s"
101.21.60.111
101.21.60.112

或者其他:

> egrep -o '([0-9]+\.){3}[0-9]+' <<< "$s"
101.21.60.111
101.21.60.112