您好我试图删除文本文件中除第一个字符串外的所有字符串。
例如:
216.158.67.20 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.2.2; http://astrolog.iqsociety.org; verifying pingback from 192.227.171.98" 188.165.206.161 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.1.1; http://www.giancarlocasaccia.com; verifying pingback from 192.227.171.98" 173.192.21.195 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/3.6; http://elsieshop.com" 69.162.134.121 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.1.5; http://www.sexyliberal.com; verifying pingback from 192.227.171.98" 192.254.140.214 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/3.5.1; http://www.kellenmeetings.com" 107.23.115.230 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.1.5; http://ccfi.com; verifying pingback from 192.227.171.98" 204.9.45.175 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/3.3.2; http://www.successfulculture.com" 66.179.133.71 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.2.2; http://www.angelsunaware.com; verifying pingback from 192.227.171.98" 76.74.128.150 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.1.5; http://www.rebeccaromero.co.uk; verifying pingback from 192.227.171.98" 204.11.50.68 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/2992; http://favors.ca" 66.185.17.226 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/3.6.1; http://www.trulynaturalskincare.net" 199.204.248.103 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/3.5; http://riselocal.com.au" 82.195.224.110 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/2.8.6; http://blog.ioolkos.com" 82.161.251.86 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.0.5; http://www.terrabits.eu; verifying pingback from 192.227.171.98" 184.154.89.138 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/3.9.3; http://websitevideocenter.com; verifying pingback from 192.227.171.98" 64.65.60.129 - - [02/Jul/2015:13:46:02 -0400] "GET / HTTP/1.0" 444 0 "-" "WordPress/4.1; http://www.railroadphotoessays.com/essays; verifying pingback from 192.227.171.98"
我只想要
216.158.67.20 188.165.206.161 173.192.21.195
等...
答案 0 :(得分:0)
您可以从使用C ++
逐行处理文件开始string line;
while (getline(file, line)) {
line.erase(remove(line.begin() + line.find_first_of(' '), line.end()), line.end());
... // do anything with line
}
由于您已标记notepad++
,因此它可以运行python脚本。尝试
file = open('logfile_name')
for line in file:
print line.split()[0]
了解如何在notepad ++中运行python脚本并使用它。