Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading Text files

Posted on 2008-06-19
3
Medium Priority
?
1,837 Views
Last Modified: 2008-06-19
Im writing a program which reads information from numerous text files and currently I am reading all the information from the text file into an array of structs then manupilating my data from there.

I am programming an option that will allow the user to see a machine history over several months due to this I need to open and read alot of text files.  As there is alot of information I dont think the way im doing it is the best solution.

SUB-BATCH,C1.0 M2.1,16-01-08,001020005013,A: ,B: 1,C:2,D: ,ID:12,0,0,0,0,0,0,5000,0,CT:,5000,0,0,0,0,RT:,0,GT:,5000,

Shown above is an example of a record stored in my text file.  Normally I would search each file based on b and c number that the user enters.  In the example above not only would I be searching for b and c number but also for type = SUB-BATCH.  All my fields are seperated by a comma and at the end of each record is a newline character.  

What I would like to know is there anyway I can go through a text file searching for the b and c number (and type in this case) find a match and only extract that record from the file without having to read the whole file.  

Few more points - some of my text files have numerous records with the same b and c number others have only one record per machine but based on the text file I always know what position in the text file that the b and c number will occur.

Any help greatly appreciated
0
Comment
Question by:lisa_mc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 1200 total points
ID: 21820494
>> without having to read the whole file.  

No.

But you could speed things up a bit by only processing those lines that start with SUB-BATCH. Ie., read in the file one line at a time, and for each line, check whether it starts with "SUB-BATCH". If so, process the line (and check the b and c values). If not, just skip the line, and go on to the next.
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 800 total points
ID: 21820993
If the lines are variable length and fields are at variable offsets, you will need to read them line by line.

It sounds to me like you'd do well to load these records into a relational database, with appropriate indexing for your queries.
0
 
LVL 3

Author Comment

by:lisa_mc
ID: 21821206
Thanks guys for both your answers now I know whats possible

Cheers
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question