Hi all
I don't have idea how to write this script, please help
I have thousand records in this format. eg: file No.3 is
File No: 003 Customer: Ann Email address: xxx@info Country: England Created by: 20071102
file No. 4 is:
File No: 004 Customer: James Email address: xxx@gov Country: Australia Created by: 20071105
I need to write a script to replace those Fields eg: (Customer/Email/Country.... when matching the FileNo.001...002...) to get Data in this file and also put the date in "Created by: 20071105" when I run this script
File NO Customer Email Address Country -------------------------------------------------------- 001 John xxx@net USA 002 Peter xxx@com Canada 003 David xxx@org Mexico
I know awk can do it. but don't know how to match the File No. in original file and the data file
Thank you for your help
____________________________________________________________________________________ Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 11/15/07, ann kok wrote:
Hi all
I don't have idea how to write this script, please help
Why was the answer you received over in the freebsd-questions list insufficient?
http://lists.freebsd.org/pipermail/freebsd-questions/2007-November/162721.ht...
- -- Andy Harrison public key: 0x67518262
ann kok wrote:
Hi all
I don't have idea how to write this script, please help
I have thousand records in this format. eg: file No.3 is
File No: 003 Customer: Ann Email address: xxx@info Country: England Created by: 20071102
file No. 4 is:
File No: 004 Customer: James Email address: xxx@gov Country: Australia Created by: 20071105
I need to write a script to replace those Fields eg: (Customer/Email/Country.... when matching the FileNo.001...002...) to get Data in this file and also put the date in "Created by: 20071105" when I run this script
File NO Customer Email Address Country
001 John xxx@net USA 002 Peter xxx@com Canada 003 David xxx@org Mexico
I know awk can do it. but don't know how to match the File No. in original file and the data file
Thank you for your help
I would think PERL would be nicely suited for this need.
================================ #!/usr/bin/perl
####################################################### # Incoming file format # --------------------------- # File No: 003 # Customer: Ann # Email address: xxx@info # Country: England # Created by: 20071102 ####################################################### # run this program in the same directory where # files to be read are stored, or set path variable # to path where files are located. ####################################################### # this code assumes that "ALL" files being read are # in exactly the format listed above #######################################################
# # path to files to be read $infiles = "./*"; # default setting assumes this program # is being run from the same directory # where the files being read exist.
# # create an array of file names to be read @records = `ls -w 1 $infiles`;
# # path to file we're creating to contain information $outfile = "./records_outfile"; # change file name # to what ever you want
open (OF, ">$outfile");
# # Output column headers to output file print OF "File No.\t\tCustomer\t\tEmail Address\t\tCountry\t\tCreated By\n";
foreach ( @records ){ chomp $_; open (F, "<$_"); foreach $r (<F>){ chomp $r; ($label,$value) = split(/:/, $r); $value =~ s/^\s+//g; # trim off any spaces before value if ($string eq "") { # first value added to string $string = $value; }else{ $string .= "\t\t$value"; } } close(F); print OF "$string\n"; }
close(OF); exit;
================================