-1

I want to pull the data out of some strings from an event log. All Event strings start with [0r(1)2[000p[040qe1w3h162[020t*. upon encountering a new one, it should parse the last string set and get some data. an example event is shown. also several events will follow themselves with no delimiter except the beginning of another event.

[0r(1)2[000p[040qe1w3h162[020t*881*11/11/2010*12:24*
 *EVENT STARTED*
[020t 12:24:06 SMARTCARD ENTERED
11\11\10     12:24     10390011
123456789098765432   6598
INVALID TRANSACTION, PLEASE CONTACT
ADMIN FOR ADVICE
-----------------------------------
[020t 12:24:52 FILE STACKED
[020t 12:24:59 FILE PRESENTED 0,5,0,0
[020t 12:25:03 FILE TAKEN
11\11\10     12:25     10390011
123456789098765432   6599
WITHDRAW          FILES10.00
[000p[040q(1     *6599*1*E*000050000,M-00,R-10200
-----------------------------------
[020t 12:25:34 SMARTCARD TAKEN
[020t 12:25:38 EVENT ENDED

I want to extract date and time as one variable for every activity. e.g.

Activity= EVENT STARTED
Activity time/date= 11/11/2010 12:24
Activity= SmartCard inserted
Activity time/date= 12:24:06

I think I've written the code to identify the start of an event with the underlisted code.

import java.util.regex.*;
public class Test 
{

    public static void main(String args[])
    {
        String line = "[0r(1)2[000p[040qe1w3h162[020t*882*11/11/2010*12:26*";        
        String[] parts = line.split("\\*");
        String date = parts[2];
        String time = parts[3];
        System.out.println("date=" + date + ", time=" + time);
    }
}

thanks

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Zigmaphi
  • 15
  • 5
  • Also consider `StreamTokenizer`, shown [here](http://stackoverflow.com/a/8867392/230513). – trashgod Sep 03 '13 at 14:45
  • shall i tell to do in java without regular expression – muthukumar Sep 03 '13 at 14:58
  • @muthukumar yes. i'd appreciate that – Zigmaphi Sep 03 '13 at 15:16
  • @trashgod i've tried using tokenizer. i can't see a way to do it using tokenizers. below is a sample code 'String str = "[020t 12:24:06 PIN ENTERED"; StringTokenizer st = new StringTokenizer(str); System.out.println("---- Split by space ------"); while (st.hasMoreElements()) { System.out.println(st.nextElement()); }' – Zigmaphi Sep 03 '13 at 15:17

1 Answers1

0
class sql
{
   public static void main (String [] args)
   {
        String dateInCase = "11/11/2010";
        String termID;
        String line = "    11\11\10     12:24     10390011";        
        String[] parts = line.split("");
        String termId = parts[4]+parts[5]+parts[6]; //to catch terminal ID
        String cardInserted = parts[1]+parts[2]+parts[3]+parts[4]+parts[5];
        String starter = parts[4]+parts[7]+parts[13]+parts[14]+parts[15];
        String tracker = parts[3]+parts[4]+parts[5]+parts[6]+parts[7];
        boolean V = (termId.matches("\\s\\d\\d"));
        boolean W = (cardInserted.matches("\\s\\s\\s\\s\\s"));//this gets card inserted
        boolean X = (starter.matches("\\D\\d\\d\\d\\d"));// a new event set has started 
        boolean Y = (tracker.matches("\\d\\d\\d\\D\\s")); // this checks for any activity as all activities have numbers in 3,4,5
        System.out.println(V);
        System.out.println(W);
        System.out.println(X);
        System.out.println(Y);

        if(V == true)
        {
            parts = line.split("\\     ");
            String terminal = parts[2];
            System.out.println("terminal " + terminal);
        }

        if(W == true)//this gets card inserted strings
        {
            parts =line.split("\\*");
            String activity = parts[1];
            System.out.print(activity);
        }

        if(X == true) //action if it sees a new event set
        {
            parts = line.split("\\*");
            String datetime = parts[2]+" "+ parts[3];
            System.out.println("time= " + datetime);
            dateInCase = parts[2];
        }

        if(Y == true) //action if it sees a new event
        {
            parts =line.split("\\ ");
            String datetime = dateInCase+ " " + parts[1];
            String activity = parts[2]+ " " + parts[3];
            System.out.println("time= " + datetime + " activity= " + activity);
        }


    }
}
Zigmaphi
  • 15
  • 5