30 lines
1.2 KiB
Awk
30 lines
1.2 KiB
Awk
# 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 <verb>` into TSV.
|
|
# usage: LC_ALL=C apt-get -s --with-new-pkgs upgrade | awk -f parse-inst.awk
|
|
# output: name<TAB>oldversion<TAB>newversion<TAB>repo
|
|
# 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
|
|
}
|