Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Newbie question - reading delimited files and printing...

Reply
Thread Tools

Newbie question - reading delimited files and printing...

 
 
Markis Landis Gardner
Guest
Posts: n/a
 
      12-24-2003
Reading files - pipe delimited or comma delimeted...
Searching for a element in one field and then showing certain fields where
element is in line.

eg...
HEHE|HI|ME|2.5
JOKE|HELLO|YOU|3.4
DONT|HI|YOU|3.4

I want all rows with YOU in second column and I want to print out 2nd and
4th columns.

SO, my answer would be
HI 2.5
HI 3.4
....

Next question...
same list only a datestamp on the end...
HEHE|HI|ME|2.5|20031223091234
JOKE|HELLO|YOU|3.4|20031223091245
DONT|HI|YOU|3.4|20031223091247
.....

1) I want all rows with YOU in second column and I want to print out 2nd and
4th columns in the 09:00:00 - 09:59:59 time frame.
2) I want an average of response time(4th field).
3) I want an average of response time broken down by hour.

Can someone help with all of this?

Please email to my home email (feel free to copy here).

http://www.velocityreviews.com/forums/(E-Mail Removed)
take out the _no_spam_

Thanks,

Markis



 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      12-24-2003
"Markis Landis Gardner" <(E-Mail Removed)> wrote in message
news:Re9Gb.5757$(E-Mail Removed)...
> Reading files - pipe delimited or comma delimeted...
> Searching for a element in one field and then showing certain fields where
> element is in line.
>
> eg...
> HEHE|HI|ME|2.5
> JOKE|HELLO|YOU|3.4
> DONT|HI|YOU|3.4


There are four basic parts to what
you need to do.

Since the last two are loops and conditionals,
I'll leave those to you.

The other two bits are:
a) IO - reading the files into Strings, and..
b) Breaking those Strings into their constituent parts.

Examples of the latter two can be seen, here..
http://www.physci.org/launcher.jsp?c...ent/URLIOFrame
http://www.physci.org/launcher.jsp?c...r/StringTokeni
zerFrame

HTH

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
 
 
 
Markis Landis Gardner
Guest
Posts: n/a
 
      12-24-2003
I tried to read the source for stringtokeni.java and it gave an error.

And I didn't understand what I was supposed to learn in the other...

Thanks,

Markis

"Andrew Thompson" <(E-Mail Removed)> wrote in message
newsThGb.64251$(E-Mail Removed)...
> "Markis Landis Gardner" <(E-Mail Removed)> wrote in message
> news:Re9Gb.5757$(E-Mail Removed)...
> > Reading files - pipe delimited or comma delimeted...
> > Searching for a element in one field and then showing certain fields

where
> > element is in line.
> >
> > eg...
> > HEHE|HI|ME|2.5
> > JOKE|HELLO|YOU|3.4
> > DONT|HI|YOU|3.4

>
> There are four basic parts to what
> you need to do.
>
> Since the last two are loops and conditionals,
> I'll leave those to you.
>
> The other two bits are:
> a) IO - reading the files into Strings, and..
> b) Breaking those Strings into their constituent parts.
>
> Examples of the latter two can be seen, here..
> http://www.physci.org/launcher.jsp?c...ent/URLIOFrame
>

http://www.physci.org/launcher.jsp?c...r/StringTokeni
> zerFrame
>
> HTH
>
> --
> Andrew Thompson
> * http://www.PhySci.org/ PhySci software suite
> * http://www.1point1C.org/ 1.1C - Superluminal!
> * http://www.AThompson.info/andrew/ personal site
>
>



 
Reply With Quote
 
Mikey
Guest
Posts: n/a
 
      12-24-2003
"Markis Landis Gardner" <(E-Mail Removed)> wrote in message news:<Re9Gb.5757$(E-Mail Removed)>.. .
> Reading files - pipe delimited or comma delimeted...
> Searching for a element in one field and then showing certain fields where
> element is in line.
>
> eg...
> HEHE|HI|ME|2.5
> JOKE|HELLO|YOU|3.4
> DONT|HI|YOU|3.4
>
> I want all rows with YOU in second column and I want to print out 2nd and
> 4th columns.
>
> SO, my answer would be
> HI 2.5
> HI 3.4
> ...


I'm confused a bit about which columns you want, because you say you
want the ones with "YOU", which would really be the 2nd column
(starting at 0), but your example output contains "HI", which isn't
the same column. So, I'll assume that "YOU" was a typo and you really
want the 2nd columns (the ones with "HI" in them.

So, something like

BufferedReader reader = new BufferedReader(new FileReader(new
File("myfile")));
while((line = reader.readLine()) ! = null) {
info = line.split("|");
if(info[1].equals("HI")) {
System.out.println(info[1] + " " + info[3]);
}
}

would probably do the job, assuming java 1.4
>
> Next question...
> same list only a datestamp on the end...
> HEHE|HI|ME|2.5|20031223091234
> JOKE|HELLO|YOU|3.4|20031223091245
> DONT|HI|YOU|3.4|20031223091247
> ....
>
> 1) I want all rows with YOU in second column and I want to print out 2nd and
> 4th columns in the 09:00:00 - 09:59:59 time frame.
> 2) I want an average of response time(4th field).
> 3) I want an average of response time broken down by hour.


Still confused about which columns.
Not sure exactly what you want in 2) & 3). For 1 do the same as my
example above except
:
if((info[4].substring(8,10)).equals("09")) {
System.out.println(info[1] + " " + info[3]);
}

>
> Can someone help with all of this?
>
> Please email to my home email (feel free to copy here).
>
> (E-Mail Removed)
> take out the _no_spam_
>
> Thanks,
>
> Markis

 
Reply With Quote
 
Markis Landis Gardner
Guest
Posts: n/a
 
      12-24-2003
Yes I made a type - sorry it was late at night.
Should have been HELLO 3.4 and HI 3.4

I only have available 1.3 - at work we do not have 1.4. Don't know if this
makes a difference.

Sorry about that.

Thanks,

Markis

"Markis Landis Gardner" <(E-Mail Removed)> wrote in message
news:Re9Gb.5757$(E-Mail Removed)...
> Reading files - pipe delimited or comma delimeted...
> Searching for a element in one field and then showing certain fields where
> element is in line.
>
> eg...
> HEHE|HI|ME|2.5
> JOKE|HELLO|YOU|3.4
> DONT|HI|YOU|3.4
>
> I want all rows with YOU in second column and I want to print out 2nd and
> 4th columns.
>
> SO, my answer would be
> HI 2.5
> HI 3.4
> ...
>
> Next question...
> same list only a datestamp on the end...
> HEHE|HI|ME|2.5|20031223091234
> JOKE|HELLO|YOU|3.4|20031223091245
> DONT|HI|YOU|3.4|20031223091247
> ....
>
> 1) I want all rows with YOU in second column and I want to print out 2nd

and
> 4th columns in the 09:00:00 - 09:59:59 time frame.
> 2) I want an average of response time(4th field).
> 3) I want an average of response time broken down by hour.
>
> Can someone help with all of this?
>
> Please email to my home email (feel free to copy here).
>
> (E-Mail Removed)
> take out the _no_spam_
>
> Thanks,
>
> Markis
>
>
>



 
Reply With Quote
 
Nunya Binness
Guest
Posts: n/a
 
      12-24-2003
Look at BufferedReader and FileReader for reading files. There are gobs
of examples of this on the 'net. Pick your poison.

As for splitting up strings by a delimiter, look at either
StringTokenizer or the .split method on String. My preference is
String.split...but to each his/her own.

-Nunya

"Markis Landis Gardner" <(E-Mail Removed)> wrote in
news:Re9Gb.5757$(E-Mail Removed):

> Reading files - pipe delimited or comma delimeted...
> Searching for a element in one field and then showing certain fields
> where element is in line.
>
> eg...
> HEHE|HI|ME|2.5
> JOKE|HELLO|YOU|3.4
> DONT|HI|YOU|3.4
>
> I want all rows with YOU in second column and I want to print out 2nd
> and 4th columns.
>
> SO, my answer would be
> HI 2.5
> HI 3.4
> ...
>
> Next question...
> same list only a datestamp on the end...
> HEHE|HI|ME|2.5|20031223091234
> JOKE|HELLO|YOU|3.4|20031223091245
> DONT|HI|YOU|3.4|20031223091247
> ....
>
> 1) I want all rows with YOU in second column and I want to print out
> 2nd and 4th columns in the 09:00:00 - 09:59:59 time frame.
> 2) I want an average of response time(4th field).
> 3) I want an average of response time broken down by hour.
>
> Can someone help with all of this?
>
> Please email to my home email (feel free to copy here).
>
> (E-Mail Removed)
> take out the _no_spam_
>
> Thanks,
>
> Markis
>
>
>


 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-25-2003
"Markis Landis Gardner" <(E-Mail Removed)> wrote in message
news:njiGb.15329$(E-Mail Removed).. .

Please do not Top-post Markis, it destroys the
thread of a conversation.

> I tried to read the source for stringtokeni.java and it gave an error.


The link was too long for newsreaders and broke, try
this one, http://www.physci.org/launcher.jsp, choose link 1.

I just checked the link on the page to both the
classes and source. Botha are there.

> And I didn't understand what I was supposed to learn in the other...


> > > Reading files - pipe delimited or comma delimeted...


...is what it shows (OK - neither of the files is pipe/comma delimited,
but same principal ). I thought that was part of the question

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Reading tab-delimited files with STL nick C++ 2 01-12-2010 03:08 AM
Re: Reading tab-delimited files with STL Jerry Coffin C++ 2 01-10-2010 06:22 PM
convert non-delimited to delimited RyanL Python 6 08-28-2007 12:06 AM
Newbie - Reading a file with delimited fields, storing first two fields in a hash AMT2K5 Perl Misc 1 11-08-2005 01:06 AM
Reading Comma Delimited Files John B. Lorenz C Programming 1 07-07-2003 11:22 PM



Advertisments