Newbie question - reading delimited files and printing...  
Author Message
Markis Landis Gardner





PostPosted: 2003-12-24 13:16:00 Top

java-programmer, Newbie question - reading delimited files and printing... 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).

email***@***.com
take out the _no_spam_

Thanks,

Markis



 
Andrew Thompson





PostPosted: 2003-12-24 23:02:00 Top

java-programmer >> Newbie question - reading delimited files and printing... "Markis Landis Gardner" <email***@***.com> wrote in message
news:Re9Gb.5757$email***@***.com...
> 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?class=/test/URLContent/URLIOFrame
http://www.physci.org/launcher.jsp?class=/codes/StringTokenizer/StringTokeni
zerFrame

HTH


 
Markis Landis Gardner





PostPosted: 2003-12-24 23:33:00 Top

java-programmer >> Newbie question - reading delimited files and printing... 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" <email***@***.com> wrote in message
news:DThGb.64251$email***@***.com...
> "Markis Landis Gardner" <email***@***.com> wrote in message
> news:Re9Gb.5757$email***@***.com...
> > 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?class=/test/URLContent/URLIOFrame
>
http://www.physci.org/launcher.jsp?class=/codes/StringTokenizer/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
>
>


 
 
sp00fd





PostPosted: 2003-12-25 0:03:00 Top

java-programmer >> Newbie question - reading delimited files and printing... "Markis Landis Gardner" <email***@***.com> wrote in message news:<Re9Gb.5757$email***@***.com>...
> 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).
>
> email***@***.com
> take out the _no_spam_
>
> Thanks,
>
> Markis
 
 
Markis Landis Gardner





PostPosted: 2003-12-25 0:47:00 Top

java-programmer >> Newbie question - reading delimited files and printing... 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" <email***@***.com> wrote in message
news:Re9Gb.5757$email***@***.com...
> 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).
>
> email***@***.com
> take out the _no_spam_
>
> Thanks,
>
> Markis
>
>
>


 
 
Nunya Binness





PostPosted: 2003-12-25 4:36:00 Top

java-programmer >> Newbie question - reading delimited files and printing... 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" <email***@***.com> wrote in
news:Re9Gb.5757$email***@***.com:

> 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).
>
> email***@***.com
> take out the _no_spam_
>
> Thanks,
>
> Markis
>
>
>

 
 
Andrew Thompson





PostPosted: 2003-12-25 11:29:00 Top

java-programmer >> Newbie question - reading delimited files and printing... "Markis Landis Gardner" <email***@***.com> wrote in message
news:njiGb.15329$email***@***.com...

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