2014-02-06 73 views
0

筛选出有效的IP地址,我在那个的/ etc/raddb /服务器RADIUS客户端配置文件,想不注释行获得有效的IP地址,所以我使用需要使用正则表达式

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /etc/raddb/server 
127.0.0.1 
192.168.0.147 

但我想忽略127.0.0.1这是评论#所以如何做到这一点?

的/ etc/raddb /服务器文件是遵循

cat /etc/raddb/server 
# pam_radius_auth configuration file. Copy to: /etc/raddb/server 
# 
# For proper security, this file SHOULD have permissions 0600, 
# that is readable by root, and NO ONE else. If anyone other than 
# root can read this file, then they can spoof responses from the server! 
# 
# There are 3 fields per line in this file. There may be multiple 
# lines. Blank lines or lines beginning with '#' are treated as 
# comments, and are ignored. The fields are: 
# 
# server[:port] secret [timeout] 
# 
# the port name or number is optional. The default port name is 
# "radius", and is looked up from /etc/services The timeout field is 
# optional. The default timeout is 3 seconds. 
# 
# If multiple RADIUS server lines exist, they are tried in order. The 
# first server to return success or failure causes the module to return 
# success or failure. Only if a server fails to response is it skipped, 
# and the next server in turn is used. 
# 
# The timeout field controls how many seconds the module waits before 
# deciding that the server has failed to respond. 
# 
# server[:port] shared_secret  timeout (s) 
#127.0.0.1  secret    1 
#other-server other-secret  3 
192.168.0.147:1812 testing123   1 
# 
# having localhost in your radius configuration is a Good Thing. 
# 
# See the INSTALL file for pam.conf hints. 
+0

其实我不知道很多关于庆典,而是以'[^#]' – Tschitsch

+0

@Tschitsch开始的正则表达式如何:谢谢,但它只返回IP地址开始#只有我想丢弃IP地址# –

+0

@alfasin:谢谢然后建议做同样的最佳途径 –

回答

1

尝试grep -o '^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /etc/raddb/server