On Tue, 14 Oct 2003 16:06:32 +0000, bastidas wrote: > Suppose I have a file with, for example, 10 lines, every one composed by > a inferior value and a superior value and a string. Every inferior value > is equal to superior value of the before line. On the other hand, I have > other file with, for example, 1000 lines with a only column of values and > I want to create another column here with the value of the string if the > value of the column is between two values (inferior-superior) of the same > line in the first file, I mean, it would be several consecutive lines > with the value of the string of the line 1 of first file, after, several > consecutive lines with the value of the string of the line 2, and so on.
Quite hard to understand what you mean, but I'll give it a try. Please have in mind that the code below is untested. Let's say that the first file has only 1 column with numbers, while the second file has 3 columns separated with one more more spaces. #!/usr/bin/perl # use strict; use warnings; my %data = (); open( F1, 'file1.txt' ) || die "$!\n"; while ( <F1> ) { chomp; s,^\s+,,; # Remove leading spaces s,\s+$,,; # Remove trailing spaces $data{ $_ } = ''; } close( F1 ); open( F2, 'file2.txt' ) || die "$!\n"; while ( <F2> ) { chomp; s,^\s+,,; # Remove leading spaces s,\s+$,,; # Remove trailing spaces my ($inf, $sup, $str) = split(/\s+/, $_, 3); foreach ( keys %data ) { if ( $_ > $inf && $_ < $sup ) { $data{ $str } = $str; } } } close( F2 ); # You might want to sort %data here foreach ( keys %data ) { print $_ . "\t" . $data{ $_ } . "\n"; } Hope this helps! -- Tore Aursand <[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]