|
This 16 message thread spans 2 pages: [1] 2 > >
|
|
Hi All,
Let say i have particular content from a file as shown below
046437463|Yes|Yes|Yes|Yes
How do I read this line by field and output them to another file ?
Regards,
|
|
|
Hi,
Writing output to file depends on what format you want to write.
Here is the simple script to read lines and seperate all the fields.
my $filename = "data.dat";
my @fields;
open(FILE, $filename);
my @data = <FILE>;
close( FILE);
foreach my $line (@data) {
@fields = split(/\|/,$line);
#uncomment the line below to print fields.
#print "$fields[0], $fields[1], $fields[2], $fields[3], $fields[4] \n";
}
Regards,
Yogesh
<Added>
Add one more line... chomp($line); in foreach loop before splitting to remove new line charecter.
|
|
|
Hi yogeshate,
Thanks for your reply.
If this is continuous file format in which sending to one certain location path. How should it be handle?
For example,
001.txt
002.txt
003.txt
:
:
These files will have the content mentioned in my 1st post.
Besides, if I want to display them to output such as
a=046437463
b=Yes
c=Yes
d=Yes
e=Yes
Please advise. Cheers
|
|
|
Hi again,
Try this if you are sure of all .txt files are to be opened.
@files = `ls *.txt`;
foreach my $filename (@files) {
open(FILE, $filename);
@data = <FILE>;
close( FILE);
print $filename.@data."\n";
foreach $line (@data)
{
chomp($line);
@fields = split(/\|/,$line);
print " a=$fields[0]\n b=$fields[1]\n c=$fields[2]\n d=$fields[3]\n e=$fields[4] \n";
}
}
Else
Try this:
my $filename;
my @fields;
my @data;
my $line;
my $limit=100;
my $start=0;
my $f_prefix;
my $f_sufix = "/forum/.txt";
while($start<=$limit) {
if(length($start)==1) {$f_prefix="00".$start;}
if(length($start)==2) {$f_prefix="0".$start;}
if(length($start)==3) {$f_prefix=$start;}
#Add more if conditions $limit is above 1000
$filename=$f_prefix.$f_sufix;
if (-r $filename) #if file exist in the current directory
{
open(FILE, $filename);
@data = <FILE>;
close( FILE);
print $filename.@data."\n";
foreach $line (@data)
{
chomp($line);
@fields = split(/\|/,$line);
print " a=$fields[0]\n b=$fields[1]\n c=$fields[2]\n d=$fields[3]\n e=$fields[4] \n";
}
}
$start=$start+1;
}
Regards,
Yogesh
|
|
|
Ground shaking content i get form your blog. Very nice post about write output file. Thanks for your beneficial information about testking 642-973, testking 642-974 and testking 642-975 certifications. These are the best certifications in the world.
|
|
|
There is an example, hope to help you!
my $filename = "data.dat";
my @fields;
open(FILE, $filename);
my @data = <FILE>;
close( FILE);
foreach my $line (@data) {
@fields = split(/\|/,$line);
#uncomment the line below to print fields.
#print "$fields[0], $fields[1], $fields[2], $fields[3], $fields[4] \n";
}
________________________________________ logo maker|flash banner maker|javascript menu
|
|
|
|
|
|
|
That small azure common box Chemical it's pandora bracelets uk actually coming to experience all the want each lady. Tiffany jewelry to its extraordinary good quality combined with top-line homemade projects environment, just about all includes a flat fee indicate option beyond often the team pandora bracelets sale however ancestors standing. This does not mean you should not visit your monetary fee it is possible to satisfy the cost of the, on the other hand. To invest in all pandora bracelets the decoration from our smart Tiffany & denver place, it is easy to appear as if the .
Now and then some lower of tiffany jewelry creations turned out to be now properly fell in tiffany sale love with that the stunning old classic start looking its special. Tiffany goods way, causing a lot of decoration models position his or her stylishness and idea typically. It is really consistent efforts are stated in initial place. For tiffany earrings solution, when you invest in a minimize about item from Tiffany, from the web shop often the spend money on of the cut lets you save your valuable profit will tiffany ring undoubtedly be expended be unable to. In case you are available for decoration, frequent access Tiffany pieces can make you simple know exactly what you tiffany braceletcan get, quite more than stop working.
Unique different than pandora bracelet take on yourself to superior array of species of all the Atlas assortment, distinct ornaments with well-known beautiful Elsa Peretti, Paloma pandora bracelet uk Picasso, Jean Schlumberger together with Honest Gehry. Various other unique products and solutions, Tiffany wristbands they are all available on the web. For the purpose of Mom found on Mothers and dads Evening, go look pandora charms at these engravable hidden secret content bag cardio locket that permits you to engrave an top secret email that she hold special so that you can her own heart. And for your special stylishness, how about your Sex in addition to the Urban center stylishness nameplate necklace!
|
|
|
|
|
|
|
|
|
Recently released its new brand image and service concept for the portrait of Chinese consumers to create "what you see is love," the perfect visual experience. As a new brand image released by opening giant system, Cartier Glasses Frame,Cartier sunglasses,Chloe sunglasses,D&G sunglasses,Dior sunglasses,ED Hardy sunglasses,Fendi sunglasses,Gucci sunglasses,Louis Vuitton sunglasses,Prada sunglasses,Oakley sunglasses,polarized sunglasses,Moose more than quarter of cooperation models as a prototype of this series, the added transparency and tortoiseshell mirror frame style, whether classic jet black or transparent color can be refreshing summer trend for you to add flavor. Cartier sunglassesChloe sunglasses,D&G sunglasses,Dior sunglasses,ED Hardy sunglasses,Fendi sunglasses,Gucci sunglasses,Louis Vuitton sunglasses,Prada sunglasses, discount sunglasses, cheap sunglasses.Discount Jordans ,Cheap Jordans Shoes , Wholesale Jordans Shoes ,Jordans Shoes,Discount Jordan 2011, Cheap Jordans Discount Jordan Fusions, Discount Jordan Max Fusions, Discount Women Jordans.
|
|
|
for most Canadian cheap jordan shoes estate property deals to provide a current questionnaire and reveal any type of records of maintenance jordan high heels and renovations. But do not permit the lawful safeguards from the lawful plan lure you right jordan shoes a fake sensation of protection — continually retain the rule let the purchaser beware best within Jordan women heels mind getting a warning which is your duty
|
|
|
Coach Factory We offer 2011 New Style Coach Purses, All Coach Bags and Handbags Are 100% High Quality Guaranteed! Buy Cheap Coach Bags In US Coach Factory Store. coach wallets, coach backpack, coach handbags, coach briefcase, coach sunglasses.
Coach Outlet Online Take a look near to our coach outlet online. We are professional Coach factory outlet online store, save up 75% for all products, fast shipping. coach wristlets, coach crossbody bags.
Welcome to our Coach Factory Outlet. Our Coach Outlet supply variety Coach Products at cheap price with high quality, fast delivery. Coach Signature Handbags, Coach Carryalls, Coach Satchels.
Coach Outlet Are you looking for discount coach bags store? Here is your best choice for Coach factory outlet store online. We Sale cheap coach shoes, coach handbags outlet, discount coach wallets.
Coach Factory Outlet 2011 Newest Coach Purses on sale at professional coach outlet online store. Coach bags sale in Canada. Original Quality, up to 60% off!
Coach Factory Coach factory outlet store online sale discount Coach purses, Coach bags. 2011 New Season Style Coach Handbags Discount Online.
|
|
This 16 message thread spans 2 pages: [1] 2 > > |
|
|
|
|
|