473,609 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading line by line in a large text file

xyz
Hi,
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line
and when i read for the next time , my program shuld read only second
line discarding first line..

i did it with ignore function but it is taking lot of time to reach
end of file...

please give me a simple approch to do this..

thanks to all
Jun 27 '08 #1
3 4744
xyz wrote:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..

ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..
I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:
http://www.cplusplus.com/reference/c...dio/ftell.html
Best Regards,

Lars
Jun 27 '08 #2
xyz
On Jun 9, 2:09*pm, Lars Uffmann <a...@nurfuersp am.dewrote:
xyz wrote:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..
ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..

I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?

In the first case, I don't see the problem, because you just read one
line after another.

In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.

For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/c...dio/ftell.html

Best Regards,

* *Lars
What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details
Jun 27 '08 #3
xyz
On Jun 9, 2:17*pm, xyz <lavanyaredd... @gmail.comwrote :
On Jun 9, 2:09*pm, Lars Uffmann <a...@nurfuersp am.dewrote:
xyz wrote:
I have a text file around 7GB includes 100 million lines...
I want to read the data line by line when I approach my module..
ie., when i read for the first time , my program shuld read only one
line and when i read for the next time , my program shuld read only
second line discarding first line..
I'm not sure what you mean by "first time" and "next time" - do you mean
subsequent read calls with the open file, or do you mean reading a line,
closing the file, then opening it again and now reading the 2nd line?
In the first case, I don't see the problem, because you just read one
line after another.
In the second case, you'll need to store a filepointer somewhere
(variable or config file) - to the position AFTER your last read (i.e.
the first byte of the succeeding line). Then when you re-open the text
file, just jump to that file pointer and continue reading.
For info on ftell & fseek, check the c++ reference:http://www.cplusplus.com/reference/c...dio/ftell.html
Best Regards,
* *Lars

What i mean is....i want the second case...
i tried storing the file positon after reading the line...
but i couldnt succeed...
could you please get some more details
i got it...thanks
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
18791
by: Rune Johansen | last post by:
Hi, I'm sorry if these questions are trivial, but I've searched the net and haven't had any luck finding the information I need. I need to perform some regular expression search and replace on a large text file. The patterns I need to match are multi-line, so I can't do it one line at a time. Instead I currently read in the entire text file in a string using the code below.
2
11748
by: Amy L. | last post by:
Is there a way through .net to read a very large text file (400MB+) backwards line by line. In system.io the filestream class has a "seek" method but the only read method requires you to know how many bytes to read in. My problem is that the line length of this log file is not constant so there is no easy way to read one line in. The only thing that is constant is that each line is terminated by a carriage return. If my only option...
9
35262
by: haibhoang | last post by:
I have a Windows Service that is trying to parse a large (> 1Gig) text file. I am keep getting OutOfMemoryException exception. Here is the code that's having problem: using (StreamReader streamReader = new StreamReader(stream, Encoding.ASCII)) { string line = ""; DateTime currentDate = DateTime.Now.Date; while (streamReader.Peek() > -1)
6
2225
by: jcrouse | last post by:
Here is a sniplet from a text file game name mapp description "Mappy (US) year 198 manufacturer "Namco history "\nMappy (c) 03/1983 Namco. \n\n- TRIVIA: \n\nLicensed to Bally Midway for US manufacture and distribution. (03/1983) \n\n- SERIES: \n\n1. Mappy \n2. Hopping Mappy \n\n0.26 \n\nBugs: \n- \"000\" is displayed on the highscore. If you get more than 30000 pts, it is displayed normally. This happens whether there are...
6
1854
by: Adrian Lin | last post by:
Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge calculations in which genetic matrices are saved in text files instead of being held in arrays that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put...
8
2087
by: hazmaz | last post by:
I am writing a program will have a function where it opens a text file, and fills a list box line by line from the text file. It works fine, except for when I tried to load a dictionary which is ~ 50mb, it appears to freeze. When I press Ctrl Alt Del I can see that it is still loading the file - the mem usage if shooting up. Its been going for a while and the memory usage is currently at verging on 600,000K. If i click on the program it...
14
11186
by: mfrsousa | last post by:
hi there, i have a huge large text file (350.000 lines) that i want to import to a MS Acccess Database, of course i don't want to use Access, but do it with C#. i already have tried the AddRow method or Insert, reading each line of the text file, the problem of course is velocity, it would take more than 4 hours to add all lines/records to the database.
13
2793
by: JJ | last post by:
I have a need to input a large tab delimited text file, which I will parse to check it has the expected columns, before allowing the user to submit it to the database. The user may paste the file into a textbox, or upload it (haven't decided yet). The problem I have is that the text file consists of around 3000 lines, and I want to display the formatted columns to the user before submitting it to the database (perhaps allowing them to...
3
16529
by: astroumut | last post by:
Hi, I need a help regarding reading a line in a text file. I have some files with columns but some header information at the top. Some of these header lines begin with a *, and some of them with nothing. I have to read the 9th line and 5th column, then extract the number from here and save it to another text file. I was thinking of some solutions. 1) I can delete the first 8 lines and read the columns straightforward. 2) I first read...
2
2853
by: deenar | last post by:
Hi I'm having problems with Java in reading the next line in a text file to execute to find a solution. My program is read the data from the text file and excute it and provide the answer on the screen.I've complied my program but can't get the program to read the next line in the text file. Please could someone help!!!Below is part of the code. class Trianglesf { public static void main(String args) { String input;
0
8130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5510
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.