in reply to Merge the difference between two files
#!/bin/perl -w use strict; use warnings; my @filenames = ("file1.txt", "file2.txt"); my %result; # Hash of arrays for my $fname(@filenames){ my $currentheader = ""; open my $f, "<", $fname or die "Cannot open '$fname' : $!"; while (my $line = <$f>){ chomp $line; next unless length($line); # Skip blank lines if ($line=~/NAME/){ $currentheader = $line; next; } push @{ $result{$currentheader} }, $line; } } # Print results for my $currentheader(sort keys %result){ print "\n$currentheader\n"; print "$_\n" for @{ $result{$currentheader} }; }
Once it hits the fan, the only rational choice is to sweep it up, package it, and sell it as fertilizer.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Merge the difference between two files
by hopper (Novice) on Jun 20, 2017 at 04:08 UTC | |
|
Re^2: Merge the difference between two files
by hopper (Novice) on Jun 16, 2017 at 18:07 UTC | |
by poj (Abbot) on Jun 16, 2017 at 19:36 UTC | |
by NetWallah (Canon) on Jun 17, 2017 at 04:53 UTC | |
by hopper (Novice) on Jun 22, 2017 at 21:12 UTC | |
by NetWallah (Canon) on Jun 23, 2017 at 19:21 UTC | |
by huck (Prior) on Jun 16, 2017 at 18:40 UTC |