in reply to Printing Columns from Two Different Files
#!/usr/bin/perl $base1 = "C:/neaq/ArcData/bluefin/data_analysis/1994sptr/data"; $base2 = "C:/neaq/ArcData/bluefin/data_dens/1994sptr"; $outfile = "C:/some/dir/to/reports"; opendir(BASE1, "$base1") || die "Cant open $base1\nReason: $!\n"; foreach $file ( grep(/\.txt$/, readdir(BASE1)) ) { warn "Skip: No matching $file in $base2\n" && next unless (-f "$base2/$file"); open(IN, "$base1/$file") || die "Cant access $file\nReason: $!\n"; while ( <IN> ) { @data1 = ( split(/\s+/) )[1,2,3,4,5,6,7]; } close(IN); open(IN, "$base2/$file") || die "Cant access $base2/$file\nReason: $!\n"; while ( <IN> ) { $data2 = ( split(/\s+/) )[3]; } close(IN); open(OUT, ">>$outfile") || die "Cant append to $outfile\nReason: $!\n"; print OUT "@data1 $data2\n"; close(OUT); } # END foreach $file readdir(BASE1) # # or alternately to save up our data and only print once # push(@out, join(' ', "$file: ", @data1, $data2)); # then loop through out once and print it out here instead #
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Printing Columns from Two Different Files
by gisrob (Novice) on Jan 31, 2003 at 19:33 UTC |