[root@gc1 ~]# grep '
request url:http:' text.sh| sed 's/
^.*url:http:\/\///g'|awk -F ":" '{print $1}'|uniq -c’
---先过滤掉没带子串的行
6 132.77.49.23
8 132.77.49.24
或方法:
[root@gc1 ~]# grep 'request url:http:' text.sh | sed 's/^.*url:http:\/\///g;s/:8003.*$//g'|uniq -c
-----将子串前面后面的全部替换为空
6 132.77.49.23
8 132.77.49.24
request url:http: 需要查找的子串的前面的一些关键字(这针对的是子串是变换的,如果子串固定,可直接写子串)
^.*url:http:\/\/ 将子串前面的字符全部替换为空,\是转义,当有元字符时使用,不复杂可不用
awk -F ":" '{print $1}' :将子串后面的第一个设置为区域分割符 打印出第一个域(即子串)
总结成万能的写法即是:
[root@gc1 ~]# grep '子串' text.sh | sed 's/^.*子串前面一段//g;s/子串后面一段.*$//g'|uniq -c
补充简单方法://和:8003分别是子串前后的
[rootgc1:/root/scripts]$ more file|grep -oP "(?<=//).*(?=:8003.*)"|sort -nr
132.77.49.24
132.77.49.23
主要应用于生产系统上比较有规律的日志啥的,如下(要查找的子串就是ip,IP在变):
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.23:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.23:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.23:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.24:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
。。。。。
。。。。。
。。。。。
。。。。。
---先过滤掉没带子串的行
6 132.77.49.23
8 132.77.49.24
或方法:
[root@gc1 ~]# grep 'request url:http:' text.sh | sed 's/^.*url:http:\/\///g;s/:8003.*$//g'|uniq -c
-----将子串前面后面的全部替换为空
6 132.77.49.23
8 132.77.49.24
request url:http: 需要查找的子串的前面的一些关键字(这针对的是子串是变换的,如果子串固定,可直接写子串)
^.*url:http:\/\/ 将子串前面的字符全部替换为空,\是转义,当有元字符时使用,不复杂可不用
awk -F ":" '{print $1}' :将子串后面的第一个设置为区域分割符 打印出第一个域(即子串)
总结成万能的写法即是:
[root@gc1 ~]# grep '子串' text.sh | sed 's/^.*子串前面一段//g;s/子串后面一段.*$//g'|uniq -c
补充简单方法://和:8003分别是子串前后的
[rootgc1:/root/scripts]$ more file|grep -oP "(?<=//).*(?=:8003.*)"|sort -nr
132.77.49.24
132.77.49.23
主要应用于生产系统上比较有规律的日志啥的,如下(要查找的子串就是ip,IP在变):
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.23:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.23:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.23:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
[375][threadname:http-8003-Processor1700][level:INFO][time:2015-03-09 09:56:36,820]request url:http://132.77.49.24:8003/OSN/BipRecei
ve/1100
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]ProcessHandler Class:com.unicom.tradeswitch.sn.Proces
[375][threadname:pool-1-thread-19732][level:INFO][time:2015-03-09 09:56:36,005]conv_id:UPAYpsns1103021201503091005414806520150309095
635815 session:com.unicom.tradeswitch.sn.util.SNSession@e11c8b
。。。。。
。。。。。
。。。。。
。。。。。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29096438/viewspace-1470752/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29096438/viewspace-1470752/