Код: Выделить всё
64.242.88.10 - - [08/Mar/2004:07:56:34 -0800] "GET /twiki/bin/search/Main/SearchResult?scope=text®ex=on&search=Web%20*Index[^A-Za-z] HTTP/1.1" 200 4163
64.242.88.10 - - [08/Mar/2004:08:04:46 -0800] "GET /SpamAssassin.html HTTP/1.1" 200 7368
p5083cd5d.dip0.t-ipconnect.de - - [08/Mar/2004:08:09:32 -0800] "GET /SpamAssassin.html HTTP/1.0" 200 7368
64.242.88.10 - - [08/Mar/2004:08:12:50 -0800] "GET /twiki/bin/view/TWiki/ChangePassword?rev=r1.6 HTTP/1.1" 200 5181
64.242.88.10 - - [08/Mar/2004:08:14:15 -0800] "GET /twiki/bin/edit/TWiki/HaroldGottschalk?t=1078717948 HTTP/1.1" 401 12846
64.242.88.10 - - [08/Mar/2004:08:15:21 -0800] "GET /twiki/bin/edit/Main/Expand_owner_alias?topicparent=Main.ConfigurationVariables HTTP/1.1" 401 12846
Код: Выделить всё
static String logEntryFormat = "^(\\S+) (\\S+) (\\S+) \\\[(.*?)\\\] "(.*?)" (\\S+) (\\S+)( "(.*?)" "(.*?)")?";
public static void countTotalBytes() throws IOException {
// First read file into an arrayList
Scanner scanner = new Scanner(accessLog);
ArrayList\ stringList = new ArrayList\();
while (scanner.hasNextLine()){
stringList.add(scanner.nextLine());
scanner.close();
//Convert to string
String listString = String.join(" ", stringList);
Pattern findBytes = Pattern.compile(logEntryFormat);
Matcher matchBytes = findBytes.matcher(listString);
// Test
if(matchBytes.matches()) {
System.out.println(matchBytes.group(7));
}
}
Я не уверен, что я подхожу к этому неправильно, но я застрял на этом несколько часов. .
Подробнее здесь: https://stackoverflow.com/questions/790 ... e-log-file
Мобильная версия