473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

append() to each row of a text file

Hello,
is it possible to append some data on a text output file appending
the data to each row, and without use too much computational I/O ??

Instead of the classical way:

VARX VARY VARZ...
year1 x1 y1 z1
year2 x2 y2 z2

... I would like to use the much more redeable:

year1 year2 ..
VARX x1 x2 ...
VARY y1 y2 ...
VARZ z1 z2 ...
....

where the 1,2 series are wrote at different times.. a sort of a
appendByRow() function.. and I would avoid of loading the whole file
in memory and then printing it line-by-line, as I have to do it on
approx 40,000 (few KB) files.. and I am worry that the second approach
would take years :-)))

is it possible to do it in a efficient way (e.g. seeking to the right
place, delete the newline and appending there) ??

Oct 16 '07 #1
3 2007
sylvaticus wrote:
Hello,
is it possible to append some data on a text output file appending
the data to each row, and without use too much computational I/O ??
There is no such thing as "each row" when files are concerned. Each
file is a stream of characters. Only your interpretation of some
specific character (like the "newline" \n for example) makes the file
*appear* to contain "rows" (we usually call them "lines").
>
Instead of the classical way:

VARX VARY VARZ...
year1 x1 y1 z1
year2 x2 y2 z2

.. I would like to use the much more redeable:

year1 year2 ..
VARX x1 x2 ...
VARY y1 y2 ...
VARZ z1 z2 ...
...

where the 1,2 series are wrote at different times.. a sort of a
appendByRow() function.. and I would avoid of loading the whole file
in memory and then printing it line-by-line, as I have to do it on
approx 40,000 (few KB) files.. and I am worry that the second approach
would take years :-)))

is it possible to do it in a efficient way (e.g. seeking to the right
place, delete the newline and appending there) ??
No. The usual approach is writing a new file where "each line" is
replicated and "expanded" to contain new information.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 16 '07 #2
On 2007-10-16 16:46, sylvaticus wrote:
Hello,
is it possible to append some data on a text output file appending
the data to each row, and without use too much computational I/O ??

Instead of the classical way:

VARX VARY VARZ...
year1 x1 y1 z1
year2 x2 y2 z2

.. I would like to use the much more redeable:

year1 year2 ..
VARX x1 x2 ...
VARY y1 y2 ...
VARZ z1 z2 ...
...

where the 1,2 series are wrote at different times.. a sort of a
appendByRow() function.. and I would avoid of loading the whole file
in memory and then printing it line-by-line, as I have to do it on
approx 40,000 (few KB) files.. and I am worry that the second approach
would take years :-)))
Files of that size is really nothing much for a modern computer, not
even if there are 40,000 of them. In fact, you could probably load them
all into memory without much trouble (though I think that it would be
faster to just open them one by one).
is it possible to do it in a efficient way (e.g. seeking to the right
place, delete the newline and appending there) ??
While such an approach would be possible it would require reading the
whole file into a buffer large enough to hold the final result, and
would involve a lot of copying making it very slow. By operating on one
line at at time you get much better memory usage and a much better design.

--
Erik Wikström
Oct 16 '07 #3
On Oct 16, 6:01 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-16 16:46, sylvaticus wrote:
Hello,
is it possible to append some data on a text output file appending
the data to each row, and without use too much computational I/O ??
Instead of the classical way:
VARX VARY VARZ...
year1 x1 y1 z1
year2 x2 y2 z2
.. I would like to use the much more redeable:
year1 year2 ..
VARX x1 x2 ...
VARY y1 y2 ...
VARZ z1 z2 ...
...
where the 1,2 series are wrote at different times.. a sort of a
appendByRow() function.. and I would avoid of loading the whole file
in memory and then printing it line-by-line, as I have to do it on
approx 40,000 (few KB) files.. and I am worry that the second approach
would take years :-)))

Files of that size is really nothing much for a modern computer, not
even if there are 40,000 of them. In fact, you could probably load them
all into memory without much trouble (though I think that it would be
faster to just open them one by one).
is it possible to do it in a efficient way (e.g. seeking to the right
place, delete the newline and appending there) ??

While such an approach would be possible it would require reading the
whole file into a buffer large enough to hold the final result, and
would involve a lot of copying making it very slow. By operating on one
line at at time you get much better memory usage and a much better design.

--
Erik Wikström
Thanks both.. I will try it opening each one at a time, and if it will
be too slow I'll go for the "normal" approach...

Oct 16 '07 #4

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

Similar topics

3
by: Charles Ranch | last post by:
Hello, I'll bet this is an elementary question. I have a text file I am converting and posting to a SQL database. But the first 15 records in this text file are going into a NOTES field in the...
2
by: bdwgarth | last post by:
I have created a DTS package which transfers data from a SQL 2000 server table to a text file. Each time the package is executed the data in the text file is replace with the new data from the...
3
by: Jonathan Buckland | last post by:
Can someone give me an example how to append data without having to load the complete XML file. Is this possible? Jonathan
2
by: JMCN | last post by:
hi i have a general question regarding append queries in access 97. each week i need to update my table(tblonlinereg) with new or modified records. firstly, i import the text file into my...
1
by: Mark | last post by:
All, Users of the database I have built receive an automated text file from one of our systems at work via e-mail. A problem with the text file exists which I have no control over. The problem is...
2
by: Gaby Sandoval | last post by:
I have this code. The user can read teh record from the text file just fine. They can click the NEXT button and it reads the next record (which is just the next line from the text file). If the...
12
by: vj | last post by:
I am using Borland C++. I run a program which generates output data files, say 'Voltage.dat', 'Current.dat'. I have a variable in my code (say N), and for various values of N (for each value of...
1
by: Semajthewise | last post by:
Hi all!! What I am trying to do today is write to a textfile then read from the file get some lines from that file and edit them. and re-write them to the file. Not replace I want the edited lines...
9
by: Phill W. | last post by:
VB.Net 2005 SP1 Windows Forms Application What's the fastest way to append text to a TextBox? I have an application that monitors data written to text files. It needs to scan some fairly...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.