The other day I had to install Debian on a new machine, and I wanted roughly the same setup as on an older machine.

You can get package lists with dpkg --get-selection, and read them with dpkg --set-selection - but that only works well if you really want to have the same packages installed.

So I wrote my own diff for dpkg --get-selection output, and its output is suitable to be cut-and-pasted to apt-get or aptitude (for installing or removal).

Being a typical, lazy Perl programmer I let Array::Diff do most of the work.

#!/usr/bin/perl use strict; use warnings; use Array::Diff; if (@ARGV != 2){ die "Usage: $0 file_1 file_2"; } my $diff = Array::Diff->diff(packages($ARGV[0]), packages($ARGV[1])); print "Packages only in '$ARGV[0]':\n"; print join(" ", @{$diff->deleted}), "\n"; print "Packages only in '$ARGV[1]':\n"; print join(" ", @{$diff->added}), "\n"; sub packages { my $fn = shift; open my $file, '<', $fn or die "Can't open file '$fn' for reading: $!"; my @packages = map { $_->[0] } grep { $_->[1] eq 'install' } map { chomp; [ split m/\s+/, $_, 2 ] } <$file>; close $file; return \@packages; }

In reply to Diff for `dpkg --get-selection` output by moritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.