java parsing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgxbytes
    New Member
    • Sep 2008
    • 25

    #1

    java parsing

    Hi,
    I have text file which contains data in this way

    DEBUG ooegroup.OoeGro upOnlineInterfa ceImpl - PERFORMANCE MEASUREMENT :: BEFORE OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:47 ICT 2009>
    DEBUG ooegroup.OoeGro upOnlineInterfa ceImpl - reserveOOEGroup :>
    DEBUG ooegroup.OoeGro upOnlineInterfa ceImpl - PERFORMANCE MEASUREMENT :: AFTER OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:48 ICT 2009>
    DEBUG reserve.Reserve OoeGroupRespons eMapper - Start : mapToOOEGroupRe sponse>


    each line starts with DEBUG

    i need to read this text and take the strings which contains PERFORMANCE MEASUREMENT and split this

    PERFORMANCE MEASUREMENT :: BEFORE OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:47 ICT 2009>

    into 1) BEFORE
    2) OOE RESERVE GROUP MEMBER Info and 3) Fri Apr 03 10:16:47 ICT 2009

    i mean to say into 3 tokens .


    Regards
    Raj
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by sgxbytes
    Hi,
    I have text file which contains data in this way

    DEBUG ooegroup.OoeGro upOnlineInterfa ceImpl - PERFORMANCE MEASUREMENT :: BEFORE OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:47 ICT 2009>
    DEBUG ooegroup.OoeGro upOnlineInterfa ceImpl - reserveOOEGroup :>
    DEBUG ooegroup.OoeGro upOnlineInterfa ceImpl - PERFORMANCE MEASUREMENT :: AFTER OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:48 ICT 2009>
    DEBUG reserve.Reserve OoeGroupRespons eMapper - Start : mapToOOEGroupRe sponse>


    each line starts with DEBUG

    i need to read this text and take the strings which contains PERFORMANCE MEASUREMENT and split this

    PERFORMANCE MEASUREMENT :: BEFORE OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:47 ICT 2009>

    into 1) BEFORE
    2) OOE RESERVE GROUP MEMBER Info and 3) Fri Apr 03 10:16:47 ICT 2009

    i mean to say into 3 tokens .


    Regards
    Raj

    What you tried so far?
    If you tried then show us the code.
    Read each line which contains "PERFORMANC E MEASUREMENT :: ".
    Then cut the string from "PERFORMANC E MEASUREMENT :: ".
    Then you tokenize the string by space deliminator.
    I think now you can have your target full filled ;)

    Comment

    • sgxbytes
      New Member
      • Sep 2008
      • 25

      #3
      lineText = lnr.readLine();
      while (lineText != null) {
      lineText = lnr.readLine();
      if (lineText != null) {
      if (lineText.conta ins("PERFORMANC E MEASUREMENT")) {
      s = lineText.toStri ng();
      String delims = "PERFORMANC E MEASUREMENT ::";
      String[] tokens = s.split(delims) ;
      System.out.prin tln(tokens[1]);

      }
      }
      }


      i have done upto this to get the string out like

      BEFORE OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:47 ICT 2009>
      AFTER OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:48 ICT 2009>

      if i use space delimiter ,i will not get the expected one

      i need the above string into 3 like

      1) BEFORE
      2) OOE RESERVE GROUP MEMBER Info
      3) Fri Apr 03 10:16:47 ICT 2009

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by sgxbytes
        lineText = lnr.readLine();
        while (lineText != null) {
        lineText = lnr.readLine();
        if (lineText != null) {
        if (lineText.conta ins("PERFORMANC E MEASUREMENT")) {
        s = lineText.toStri ng();
        String delims = "PERFORMANC E MEASUREMENT ::";
        String[] tokens = s.split(delims) ;
        System.out.prin tln(tokens[1]);

        }
        }
        }


        i have done upto this to get the string out like

        BEFORE OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:47 ICT 2009>
        AFTER OOE RESERVE GROUP MEMBER Info >>>> Fri Apr 03 10:16:48 ICT 2009>

        if i use space delimiter ,i will not get the expected one

        i need the above string into 3 like

        1) BEFORE
        2) OOE RESERVE GROUP MEMBER Info
        3) Fri Apr 03 10:16:47 ICT 2009

        See now you cut the last character ... just you can do it during "substring" just last parameter will be "length-1".
        Then tokenize on the basis of space deliminator. Then take the first token as your desired first token then keep adding untill ">>>>" token encounters to get the second one then rest is last desired token ;)

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Have a look at
          [code=java]
          String regex = "(BEFORE|AFTER) .*?>>>>.+?>DEBU G";
          Pattern p = Pattern.compile (regex, Pattern.MULTILI NE);
          Matcher m = p.matcher(s);
          while (m.find()) {
          String line = m.group();
          String[] pieces = line.split(">") ;
          System.out.prin tln(Arrays.toSt ring(pieces));
          }
          [/code]
          After you have those pieces in an array you can then play with them at your leisure.

          Comment

          Working...