Is it posible to append to txt file vertically???
Example original file... (constants: A, B , C, Car, Boat) - BLANK, Car, BLANK, Boat, BLANK
-
BLANK, Nov07, Dec07, Nov07, Dec07
-
A, 1, 2, 2, 7,
-
B, 1, 2, 2, 7,
-
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.. - BLANK, Car, BLANK, BLANK, Boat, BLANK, BLANK
-
BLANK, Nov07, Dec07, Jan08, Nov07, Dec07, Jan08
-
A, 1, 2, 3, 2, 7, 4
-
B, 1, 2, 4, 2, 7, 4
-
C, 1, 2, 5, 2, 7, 5
Thanks.
4 2285
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
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.
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
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: -
use strict;
-
use warnings;
-
-
open(DATA,"data.txt") or die "data open failed:$!";
-
open(UPDATE,"update.txt") or die "update open failed:$!";
-
open(RES,">result.txt") or die "create failed:$!";
-
-
my @update;
-
##take data for updating into an array
-
while(<UPDATE>){chomp; push @update,$_ ;}
-
while(<DATA>) {
-
my @fields=split(/,/,$_); ##splitting on commas
-
splice(@fields,2,0,shift(@update)); ##inserting in position:3/index:2
-
my $res=join(",",@fields); ##joining elements with coma
-
print RES $res;
-
}
-
close(DATA);close(UPDATE); close(RES);
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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?
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
| |