Newbie question - reading delimited files and printing...

Discussion in 'Java' started by Markis Landis Gardner, Dec 24, 2003.

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


    take out the _no_spam_

    Thanks,

    Markis
    Markis Landis Gardner, Dec 24, 2003
    #1
    1. Advertising

  2. "Markis Landis Gardner" <> wrote in message
    news:Re9Gb.5757$...
    > 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
    Andrew Thompson, Dec 24, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:DThGb.64251$...
    > "Markis Landis Gardner" <> wrote in message
    > news:Re9Gb.5757$...
    > > 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
    >
    >
    Markis Landis Gardner, Dec 24, 2003
    #3
  4. Markis Landis Gardner

    Mikey Guest

    "Markis Landis Gardner" <> wrote in message news:<Re9Gb.5757$>...
    > 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).
    >
    >
    > take out the _no_spam_
    >
    > Thanks,
    >
    > Markis
    Mikey, Dec 24, 2003
    #4
  5. 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" <> wrote in message
    news:Re9Gb.5757$...
    > 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).
    >
    >
    > take out the _no_spam_
    >
    > Thanks,
    >
    > Markis
    >
    >
    >
    Markis Landis Gardner, Dec 24, 2003
    #5
  6. 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" <> wrote in
    news:Re9Gb.5757$:

    > 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).
    >
    >
    > take out the _no_spam_
    >
    > Thanks,
    >
    > Markis
    >
    >
    >
    Nunya Binness, Dec 24, 2003
    #6
  7. "Markis Landis Gardner" <> wrote in message
    news:njiGb.15329$...

    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
    Andrew Thompson, Dec 25, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John B. Lorenz

    Reading Comma Delimited Files

    John B. Lorenz, Jul 7, 2003, in forum: C Programming
    Replies:
    1
    Views:
    3,626
    Joe Wright
    Jul 8, 2003
  2. RyanL
    Replies:
    6
    Views:
    681
    Paul McGuire
    Aug 28, 2007
  3. Jerry Coffin
    Replies:
    2
    Views:
    914
  4. nick
    Replies:
    2
    Views:
    418
  5. AMT2K5
    Replies:
    1
    Views:
    191
    Eric Schwartz
    Nov 8, 2005
Loading...

Share This Page