I am fairly new at java, and would like to request your help.
Here is my goal, I have a text file with log information that is not consistent.
example log file content:
mai 6 03:26:53 macbookscuba Dock[215]: Corrupt JPEG data: premature end of data segment
mai 6 03:26:53 macbookscuba [0x0-0xa00a].com.apple.dock[215]:
Tue mai 6 03:26:53 macbookscuba.local Dock[215] <Error>: Corrupt JPEG data: premature end of data segment
mai 6 09:28:51 localhost com.apple.kextd[10]: __ZN16IO80211Interface11postMessageEi
mai 6 09:28:51 localhost com.apple.kextd[10]: __ZN16IO80211Interface22monitorModeInputPacketEP6__mbuf
mai 6 09:28:51 localhost com.apple.kextd[10]: __ZN17IO80211Controller20outputRaw80211PacketEP16IO80211InterfaceP6__mbuf
mai 6 09:28:51 localhost kernel[0]: Previous Shutdown Cause: -60
mai 6 09:28:51 localhost kextd[16]: kld_load_from_memory() failed for module /System/Library/Extensions/IO80211Family.kext/Contents/PlugIns/AirPortAtheros5424.kext/Contents/MacOS /AirPortAtheros5424
I would like to Parse this text file and obtain statistics for:
- Number of messages per minute.
- Number of messages per hour.
- Number of messages per day.
As you probably noticed there is a "Tue" that randomly shows up before my date.
What I was thinking of doing was taking the content of hte text file, and placing it in an array, then count the number of times I see mai 6, then the number of hours, then the number of times I see the same minutes.
unfortunatly I have to admit I am a little lost on how to go obtaining my goal. And my result is not what I wish, furthermore I do not know how to go about breaking down the hour/minute/secondes?
Here is what I have so far:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ArrayTest
{
public static void main(String[] arg)
{
String[] month = new String[100];
String[] day = new String[100];
String[] time = new String[100];
String[] appName = new String[100];
String[] port = new String[100];
String[] message = new String[100];
int counter = 0;
try {
Scanner input = new Scanner(new File("data.txt"));
while(input.hasNext()) {
month[counter] = input.next();
day [counter] = input.next();
time[counter] = input.next();
appName[counter] = input.next();
port[counter] = input.next();
message[counter] = input.next();
System.out.println(counter + " month" + month[counter] + " day:" + day[counter] + " time:" + time[counter] + " appName:" + appName[counter] + " port:" + port[counter] + " message:" + message[counter]);
counter++;
}
} catch (FileNotFoundException e) {
}
}
}
Thank you in advance to point me in the right direction,
John

New Topic/Question
Reply




MultiQuote





|