Newbie question - reading delimited files and printing...

  • Thread starter Markis Landis Gardner
  • Start date
M

Markis Landis Gardner

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 address removed)
take out the _no_spam_

Thanks,

Markis
 
A

Andrew Thompson

Markis Landis Gardner said:
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
 
M

Markis Landis Gardner

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
 
M

Mikey

Markis Landis Gardner said:
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]);
}
 
M

Markis Landis Gardner

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
 
N

Nunya Binness

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
 
A

Andrew Thompson

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...

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top