To update one file with the another file's data..




Hi,

I have two text files: each one has has four fields (delimited by a
space) on each line: id, group, email and manager_id. First file is a
small file with 50 entries and the second one is a huge file with
5,000 entries. The "id" field is same in both files, but the
manager_id's may be different. By comparing all the entries in the
second file (that has the correct manager id), I need to update the
manager_id field in the first file.

Here is the code, I am thinking of:

-----------------------------------------
open (INPUT1,"smallFile.txt") or die "Cannot open the file: $!";
open (INPUT2,"bigFile.txt") or die "Cannot open the file: $!";


while $line1 (<INPUT1>)
{
@small_arr = split /\s+/, $line1;
}

while $line2 (<INOUT2>)
{
@big_arr = split /\s+/, $line2;
}


foreach (@small_arr)
{
if ($small_arr[0] == $big_arr[0] ) # first ID is same in both
files
{
$small_arr[3] = $big_arr[3];
print "$_\n";
}
}

-------------------------------------------------

I know some thing is certainly wrong here. can some one tell me pl.?

Thanks,
J
.



Relevant Pages

  • Merge two excel files
    ... I have two excel files with the same cell layout. ... entries in the first file are identical to the second file. ...
    (microsoft.public.excel)
  • Re: To update one file with the another files data..
    ... 5,000 entries. ... manager_id field in the first file. ... I chose to use 'Tie::File' for updating 'smallFile.txt'. ... # Put the data of 'bigFile.txt' into %bighash; ...
    (comp.lang.perl.misc)
  • Re: Interesting data storage problem
    ... > write out to files a fair amount of data, on the rough order of 10 MB. ... number is the block's location in the second file. ... specifically recorded in the first file. ... the record data along with the extra data position and size. ...
    (comp.lang.java.programmer)
  • Re: Error: Missing operand
    ... screen and finish loading and displaying the first file, ... second file to load without errors. ... For both Fireworkz and Fireworkz Pro the splash screen is displayed by a ... WaitUntil Running "Fireworkz Pro" ...
    (comp.sys.acorn.misc)
  • Re: Working with two input files
    ... First file: data1 data2 data3 ... Second file: 00:01 begin block 00:02 text data1 00:03 end block 01:10 begin block 01:11 text data2 01:12 end block 01:30 begin block 01:31 text data1 01:32 other data 01:33 end block 01:51 begin block 02:12 text data4 02:13 end block 02:11 begin block 02:12 text data3 ... from first file and don't output blocks with data, ... load it string by string and run script with different values of data, ...
    (comp.lang.awk)