in reply to compare 2 files and print to a third
I took a liberty and rephrased your question. I hope I got it right.
I am wondering how to take 2 different files whose lines have a unique key called $login. This key is at the beginning of the line and it is the only piece of information common to the records. I would like to go through the file, line by line, and concatenate the contents of all the lines with the same keys, which I will output to a third file.
To do this, you will want to read in both files, and isolate $login and use it as a hash key. (So far, so good.) So use a regular expression or split (or something) and do
if ( exists ( $hash{$login} ) ) { $hash{$login} .= $delimiter . $_; } else { $hash{$login} = $_; }
Then, once you are done, you will want to print out your hash.
foreach my $key (keys %hash) { print "$key : $hash{$key}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: compare 2 files and print to a third
by BrowserUk (Patriarch) on Nov 06, 2003 at 00:38 UTC | |
by allolex (Curate) on Nov 06, 2003 at 07:13 UTC |