in reply to subset extraction from master file

Yet another way:

$ cat master key1 other 1 stuff key2 other 2 stuff key3 other 3 stuff $ cat subset key1 more 1 stuff key3 more 3 stuff $ cat ex.pl #!/usr/bin/perl -w use strict; my %hash; while(<>){ chomp; my($key, $rest) = split " ",$_,2; $hash{$key} = $rest and next if 1 .. eof; $hash{$key} .= " $rest" if exists $hash{$key}; } for (sort keys %hash){ print "$_ $hash{$_}\n"; } __END__ $ perl ex.pl subset master key1 more 1 stuff other 1 stuff key3 more 3 stuff other 3 stuff