Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-16-2007, 10:10 AM   #1
Registered: Apr 2006
Posts: 49

Rep: Reputation: 15
Cool [C++] append to each row of a text files

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 on different times.. a sort of a appendByRow() function.. and I would avoid of load the whole file in memory and then printing it line-by-line..

is it possible ??
Old 10-17-2007, 05:36 AM   #2
Senior Member
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
To achieve that you will need to read in the entire file append the data to each line before writing it back out again, so no simple solution, compared with appending the new year to the end of the file.
Old 10-18-2007, 08:22 AM   #3
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Is this a one-time task? Do you just have one file to transpose or are you needing to create a program which will maintain this matrix?


c++, file, text

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I append text to a string in a file HGeneAnthony Linux - Newbie 4 03-01-2007 01:16 PM
sed script to append variable text gmartin Linux - General 4 12-27-2006 05:44 PM
quickly append text to file blackzone Linux - General 3 09-07-2006 06:48 AM
Delete the first row from a text file loopoo Linux - Newbie 2 08-15-2006 03:57 AM
batch append string to the end of a determined line in text files osio Programming 6 06-30-2005 10:28 AM

All times are GMT -5. The time now is 07:19 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration