# SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2026 Bryan Joshua Pedini # parse-inst.awk - parse the "Inst" lines of `LC_ALL=C apt-get -s ` into TSV. # usage: LC_ALL=C apt-get -s --with-new-pkgs upgrade | awk -f parse-inst.awk # output: nameoldversionnewversionrepo # oldversion is "-" for packages that are newly installed (no previous version); # repo is the raw origin list, e.g. "Ubuntu:24.04/noble-updates, Ubuntu:24.04/noble-security" # (may be empty for packages coming from a local .deb). POSIX awk, tested with mawk 1.3.4. /^Inst / { name = $2 rest = $0 sub(/^Inst [^ ]+ /, "", rest) old = "-" if (substr(rest, 1, 1) == "[") { # "[old] (new origins [arch])" old = rest sub(/^\[/, "", old) sub(/\].*$/, "", old) sub(/^\[[^]]*\] /, "", rest) } sub(/^\(/, "", rest) # "new origins [arch]) ..." new = rest sub(/ .*$/, "", new) sub(/^[^ ]+ ?/, "", rest) # "origins [arch]) ..." i = index(rest, "])") repo = substr(rest, 1, i - 1) # "origins [arch" sub(/ ?\[[^[]*$/, "", repo) # drop " [arch" printf "%s\t%s\t%s\t%s\n", name, old, new, repo }