Parsing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyohere
    New Member
    • Apr 2007
    • 73

    #1

    Parsing

    I have a text file containing lot of data organised in a manner......i want to know which is the efficient way in java to parse such a file.......
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by jyohere
    I have a text file containing lot of data organised in a manner......i want to know which is the efficient way in java to parse such a file.......
    Depends on the manner in which the data is organised and the reason for parsing the file.
    Do you want to extract certain fields from it or do you want to search for certain patterns e.t.c?

    Comment

    • jyohere
      New Member
      • Apr 2007
      • 73

      #3
      Originally posted by r035198x
      Depends on the manner in which the data is organised and the reason for parsing the file.
      Do you want to extract certain fields from it or do you want to search for certain patterns e.t.c?
      The text file is organised as space separated fields....there are many entries .....for example, i have a date field along with all other fields...i want to get the entries which are between a range of dates in the file......

      i.e ...the file looks like

      Cid Ctype 2 PortID j k l m EntytyType 0 0 0 20070508164501 Job123456789123 456789123456789 123456Note Circuit12345123 456789123456789 123456Name 5 10 20

      Cid Ctype 2 PortID j k l m EntytyType 0 0 0 20070508164502 Job123456789123 456789123456789 123456Note Circuit12345123 456789123456789 123456Name 5 10 20

      20070508164501 is the date...i want the entries between 20070508164500 and
      20070508164515

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by jyohere
        The text file is organised as space separated fields....there are many entries .....for example, i have a date field along with all other fields...i want to get the entries which are between a range of dates in the file......

        i.e ...the file looks like

        Cid Ctype 2 PortID j k l m EntytyType 0 0 0 20070508164501 Job123456789123 456789123456789 123456Note Circuit12345123 456789123456789 123456Name 5 10 20

        Cid Ctype 2 PortID j k l m EntytyType 0 0 0 20070508164502 Job123456789123 456789123456789 123456Note Circuit12345123 456789123456789 123456Name 5 10 20

        20070508164501 is the date...i want the entries between 20070508164500 and
        20070508164515
        Have a look at this and see what you can get out of it. Post if you need more help.

        Comment

        • jyohere
          New Member
          • Apr 2007
          • 73

          #5
          Originally posted by r035198x
          Have a look at this and see what you can get out of it. Post if you need more help.
          It is not of much help......So pls help

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by jyohere
            It is not of much help......So pls help
            That's unfortunate because that's as much as I was going to post here anyway.

            I 'don't see how it fails to help you though since it talks about reading a file which is what you want to do.

            Comment

            • jyohere
              New Member
              • Apr 2007
              • 73

              #7
              Originally posted by r035198x
              That's unfortunate because that's as much as I was going to post here anyway.

              I 'don't see how it fails to help you though since it talks about reading a file which is what you want to do.
              I want to read on a field by field basis say

              Name Age DateOfBirth

              Jyo 25 28-11-82
              Ram 30 20-12-81



              say I want to read the above file and find out the entries whose DOB is between two given dates

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by jyohere
                I want to read on a field by field basis say

                Name Age DateOfBirth

                Jyo 25 28-11-82
                Ram 30 20-12-81



                say I want to read the above file and find out the entries whose DOB is between two given dates
                Are you able to read a file line by line say into an array?

                Comment

                • jyohere
                  New Member
                  • Apr 2007
                  • 73

                  #9
                  Originally posted by r035198x
                  Are you able to read a file line by line say into an array?
                  There is a problem in that too.....the number of rows is not known.....it gets changed dynamically.... .so i cannot fix the size if i use a 2d array

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by jyohere
                    There is a problem in that too.....the number of rows is not known.....it gets changed dynamically.... .so i cannot fix the size if i use a 2d array
                    Well you don't have to read it into an array. I just wanted to make sure you are able to read data from a textfile.

                    Now do you know that you can split a string into a String array using the split method? e.g
                    Code:
                     String s = "This string"; 
                    String[] items = s.split(" ");

                    Comment

                    • jyohere
                      New Member
                      • Apr 2007
                      • 73

                      #11
                      Originally posted by r035198x
                      Well you don't have to read it into an array. I just wanted to make sure you are able to read data from a textfile.

                      Now do you know that you can split a string into a String array using the split method? e.g
                      Code:
                       String s = "This string"; 
                      String[] items = s.split(" ");
                      what u said can be done only for one line....wat if i have muliple lines and i do not know the number of lines

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by jyohere
                        what u said can be done only for one line....wat if i have muliple lines and i do not know the number of lines
                        Like has been shown in the link I gave you, you can read a whole file using a loop structured as
                        Code:
                         while((line = input.readLine()) != null) { 
                         
                        }
                        Where do you want to extract the records to?

                        Comment

                        Working...