Search code examples
bashawksedgrepcut

how to colate a list of installed packages into a "one-liner" for re-installing later (using only grep / cut / sed / awk etc, no external tools)


Command: apt list --installed

Output:

aapt/stable,now 7.1.2.33-7 aarch64 [installed]
abduco/stable,now 0.6-2 aarch64 [installed]
ack-grep/stable,now 3.3.1 all [installed]
antibody/stable,now 6.0.1 aarch64 [installed]
apt/stable,now 1.4.9-27 aarch64 [installed]

I would like:

aapt abduco ack-grep antibody apt

Therefore I need:

Only up-to the first / in the first field, but shown in one line, not multiple.

Background info:

  • I would like to backup a list of installed packages,
  • But only the name of the package, nothing else,
  • Shown on one line.

This list can then be appended with sudo apt install to make a quick one-liner for re-installing my packages later on, once I have wiped my system.


Solution

  • This may help you:
    apt list --installed | awk -F'/' '{print $1}' | tr '\n' ' '

    apt list --installed list the packages.
    awk -F'/' '{print $1}' take the first column using / as separator.
    tr '\n' ' ' replace the jump lines for spaces.