britney has asked for the wisdom of the Perl Monks concerning the following question:
1. A.txt 1|||GoRaiders|0473H30DF|123456|Oakland||Test|TD|07/02/2002|01/05/2003| 2|||GoRaiders|019H4151|544419|SpareX||Test|TD|07/02/2002|01/05/2003| 3|||GoRaiders|019H4152|544420|SpareX||Test|TD|07/02/2002|01/05/2003| 4|||GoRaiders||548420|SpareX||Test|TD|07/02/2002|01/05/2003| 5|||GoRaiders||548419|SpareX||Test|Smith|07/02/2002|01/05/2003| 6|||GoRaiders|902F2416|492487|SpareX||Test|TD|08/02/2002|01/20/2003| 7|||GoRaiders|019H4154|544821|SpareX||Test|TD|07/02/2002|01/20/2003| 8|||GoRaiders|924H2CEC|492489|SpareX||Test|TD|07/02/2002|01/20/2003| 2. B.txt 1|TD|01/10/2003|07/11/2003|SpareX|666666||||texas|Yes|Yes|Yes|This is +a test. Please ignore 2|TD|01/10/2003|07/11/2003|SpareX|664464||||newyork|Yes|Yes|Yes|This i +s a test. Please ignore 3|Britney|01/10/2003|07/11/2003|M3|464444|911H3233|||california|Yes|Ye +s|No| 4|TD|01/10/2003|07/11/2003|SpareX|3333333||||texas|Yes|Yes|Yes|This is + a test. Please ignore 5|TD|01/10/2003|07/11/2003|SpareX|4444444||||newyork|Yes|Yes|Yes|This +is a test. Please ignore 6|Britney|01/10/2003|07/11/2003|M3|555555|00000888|||california|Yes|Ye +s|No| 7|TD|01/12/2003|07/11/2003|SpareX|123456||||texas|Yes|Yes|Yes|This is +a test. Please ignore 8|TD|01/12/2003|07/11/2003|SpareX|544419||||newyork|Yes|Yes|Yes|This i +s a test. Please ignore 9|Britney|01/12/2003|07/11/2003|M3|544420|666688855|||california|Yes|Y +es|No|
1|||GoRaiders|0473H30DF|123456|Oakland||Test|TD|01/12/2003|07/11/2003| 2|||GoRaiders|019H4151|544419|SpareX||Test|TD|01/12/2003|07/11/2003| 3|||GoRaiders|019H4152|544420|SpareX||Test|TD|01/12/2003|07/11/2003| 4|||GoRaiders||548420|SpareX||Test|TD|07/02/2002|01/05/2003| 5|||GoRaiders||548419|SpareX||Test|Smith|07/02/2002|01/05/2003| 6|||GoRaiders|902F2416|492487|SpareX||Test|TD|08/02/2002|01/20/2003| 7|||GoRaiders|019H4154|544821|SpareX||Test|TD|07/02/2002|01/20/2003| 8|||GoRaiders|924H2CEC|492489|SpareX||Test|TD|07/02/2002|01/20/2003|
#!/usr/bin/perl use strict; use warnings; open FILEB, 'B.txt' or die "B: $!\n"; while (<FILEB>) { my ($id,$add, $expire) = (split /\|/)[5,2,3]; open FILEA, 'A.txt' or die "A: $!\n"; open NEWA, '>A.txt.new' or die "New A: $!\n"; while (<FILEA>) { if (/\|$id\|/) { my @rec = split /\|/; @rec[10, 11] = ($add, $expire): $_ = join ('|', @rec); } print NEWA, $_; } close FILEA; close NEWA: } rename 'A.txt.new', 'A.txt';
Code tags added for data - dvergin 2003-01-12
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: update flat file
by AcidHawk (Vicar) on Jan 13, 2003 at 06:24 UTC | |
|
Re: update flat file
by dvergin (Monsignor) on Jan 13, 2003 at 06:28 UTC | |
by britney (Acolyte) on Jan 14, 2003 at 17:11 UTC | |
|
Re: update flat file
by OM_Zen (Scribe) on Jan 13, 2003 at 21:02 UTC |