473,385 Members | 1,872 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,385 software developers and data experts.

is it posible to append to txt file vertically?

Is it posible to append to txt file vertically???
Example original file... (constants: A, B , C, Car, Boat)
Expand|Select|Wrap|Line Numbers
  1. BLANK,    Car,    BLANK,    Boat,    BLANK
  2. BLANK,    Nov07,    Dec07,    Nov07,    Dec07
  3. A,    1,    2,    2,    7,
  4. B,    1,    2,    2,    7,
  5. C,    1,    2,    2,    7,
when come to january, i wish to add the Jan 08 data (for noth car and boat respectively into the previous data), it should be adding to vertically right of the dec 07 data..

Expand|Select|Wrap|Line Numbers
  1. BLANK,    Car,    BLANK,    BLANK,    Boat,    BLANK,    BLANK
  2. BLANK,    Nov07,    Dec07,    Jan08,    Nov07,    Dec07,    Jan08
  3. A,    1,    2,    3,    2,    7,    4
  4. B,    1,    2,    4,    2,    7,    4
  5. C,    1,    2,    5,    2,    7,    5

Thanks.
Mar 22 '08 #1
4 2285
eWish
971 Expert 512MB
I believe that there are some modules that will let you append the file in the middle. However, I think that you would have to read the entire line and add the data to it. Then append the file. I would search CPAN for the Tie::File module. Going off memory, so I could be wrong here.

--Kevin
Mar 22 '08 #2
KevinADC
4,059 Expert 2GB
It is possible but it is not a standard function or standard filehandle option. You would have to write code to append data to the ends of lines or ends of specific lines.
Mar 22 '08 #3
Thanks for the inputs.
Could anyone show me the code on how to add in the whole column to the file?

____Original text file___
A,1,2
B,1,2
C,1,2
D,1,2

__column to be input__
NEWA
NEWB
NEWC
NEWD


___OutputFile___
A,1,NEWA,2
B,1,NEWB,2
C,1,NEWC,2
D,1,NEWD,2
Mar 23 '08 #4
nithinpes
410 Expert 256MB
Thanks for the inputs.
Could anyone show me the code on how to add in the whole column to the file?

____Original text file___
A,1,2
B,1,2
C,1,2
D,1,2

__column to be input__
NEWA
NEWB
NEWC
NEWD


___OutputFile___
A,1,NEWA,2
B,1,NEWB,2
C,1,NEWC,2
D,1,NEWD,2
This can be done easily if you know the column number/field number where you want to insert data. Else, you have to calculate the field number by searching for a keyword(like 'Dec 07' in your initial example).
For the above case, where data need to be inserted in 3rd column/field, the following code works:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. open(DATA,"data.txt") or die "data open failed:$!";
  5. open(UPDATE,"update.txt") or die "update open failed:$!";
  6. open(RES,">result.txt") or die "create failed:$!";
  7.  
  8. my @update;
  9. ##take data for updating into an array
  10. while(<UPDATE>){chomp; push @update,$_ ;} 
  11. while(<DATA>) {
  12.   my @fields=split(/,/,$_);  ##splitting on commas
  13.   splice(@fields,2,0,shift(@update)); ##inserting in position:3/index:2
  14.   my $res=join(",",@fields);  ##joining elements with coma
  15.   print RES $res;
  16. }
  17. close(DATA);close(UPDATE);  close(RES);
  18.  
Mar 25 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: George Ziniewicz | last post by:
.. I try to use CSS when possible, though I am still learning and don't maximize its use. In particular, I still use a table to provide for a centered image in a few slideshows (though table...
27
by: FL | last post by:
Hi Everyone, I know howto center a block using margin-left: auto ; margin-right: auto ; but I'm trying to center vertically a box, any idea to solve this?
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
3
by: ghadley_00 | last post by:
Hi, I have a MS access database into which I need to import a text file that is oriented vertically (fields are listed from top to bottom with the value for each field appearing to the right of...
5
by: Simone M | last post by:
Here is my problem: I need to append a string to a file every time the user downloads this file. The string is different for every user. I would like to append the string to the file via ftp. But...
1
by: Grzegorz ¦lusarek | last post by:
Hi All. One of the fields used in my form is to upload file, Is is to posible to made this field readonly and after filling radio field set this to use by javascript. I don't wanna give a User...
11
by: panic attack | last post by:
Hello everbody, Our system is using Sql Server 2000 on Windows XP / Windows 2000 We have a text file needs to be imported into Sql Server 2000 as a table. But we are facing a problem which is,...
2
by: cleelakumar | last post by:
helloo.., i am leela kumar. my problem is if any file can be explor view in vb.net 1.1, let me known if any processs,any code. plz slove the problem hi all, i have a small problem.Can I open...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.