Connecting Tech Pros Worldwide Forums | Help | Site Map

Parsing

Member
 
Join Date: Apr 2007
Posts: 77
#1: May 8 '07
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.......

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: May 8 '07

re: Parsing


Quote:

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?
Member
 
Join Date: Apr 2007
Posts: 77
#3: May 8 '07

re: Parsing


Quote:

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 Job123456789123456789123456789123456Note Circuit12345123456789123456789123456Name 5 10 20

Cid Ctype 2 PortID j k l m EntytyType 0 0 0 20070508164502 Job123456789123456789123456789123456Note Circuit12345123456789123456789123456Name 5 10 20

20070508164501 is the date...i want the entries between 20070508164500 and
20070508164515
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#4: May 8 '07

re: Parsing


Quote:

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 Job123456789123456789123456789123456Note Circuit12345123456789123456789123456Name 5 10 20

Cid Ctype 2 PortID j k l m EntytyType 0 0 0 20070508164502 Job123456789123456789123456789123456Note Circuit12345123456789123456789123456Name 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.
Member
 
Join Date: Apr 2007
Posts: 77
#5: May 8 '07

re: Parsing


Quote:

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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: May 8 '07

re: Parsing


Quote:

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.
Member
 
Join Date: Apr 2007
Posts: 77
#7: May 8 '07

re: Parsing


Quote:

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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#8: May 8 '07

re: Parsing


Quote:

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?
Member
 
Join Date: Apr 2007
Posts: 77
#9: May 8 '07

re: Parsing


Quote:

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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#10: May 8 '07

re: Parsing


Quote:

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
Expand|Select|Wrap|Line Numbers
  1.  String s = "This string"; 
  2. String[] items = s.split(" ");
  3.  
Member
 
Join Date: Apr 2007
Posts: 77
#11: May 8 '07

re: Parsing


Quote:

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

Expand|Select|Wrap|Line Numbers
  1.  String s = "This string"; 
  2. String[] items = s.split(" ");
  3.  

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
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#12: May 8 '07

re: Parsing


Quote:

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
Expand|Select|Wrap|Line Numbers
  1.  while((line = input.readLine()) != null) { 
  2.  
  3. }
  4.  
Where do you want to extract the records to?
Reply