[GLLUG] Merging Records in Input
Mike Brodbelt
mike at coruscant.org.uk
Thu Dec 5 23:17:08 UTC 2013
On 05/12/13 22:38, Mick Farmer wrote:
> Dear GLLUGers,
>
> I have an input consisting of two fields such as
<snip>
> I'm sure there's a UNIX utility that does this (sort?, uniq?) but can't
> currently find it. Can anyone help?
I believe the utility you're looking for might be called "perl"....
$ perl -n -e 'while (<>) {chomp; ($k,$v) = split(/\s+/);
push(@{$h{$k}},$v)} foreach (sort {$a<=>$b} keys %h) {print $_ . " " .
join(" ",@{$h{$_}}) ."\n";}' < input
7 060b
8 003d 003g 005n 008c 010a
9 100c
11 005m 013a
HTH,
Mike
More information about the GLLUG
mailing list