From af4cf20b460835721ed04147bb36f31c8b5c766f Mon Sep 17 00:00:00 2001 From: Filippo Giunchedi Date: Tue, 12 Dec 2017 10:45:59 +0100 Subject: [PATCH] apt.sh: handle multiple origins in apt-get output (#757) It might happen that a given upgrade comes from multiple origins, in which case the origins are separated by ", " and thus breaking whitespace-based split. For example: Inst package [1.2.3] (1.2.4 Debian:8.10/oldstable, Debian-Security:8/oldstable [amd64]) To workaround this case, mangle the apt-get output to remove whitespaces from the origins list. --- text_collector_examples/apt.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/text_collector_examples/apt.sh b/text_collector_examples/apt.sh index 3919b7c5..1dddf454 100755 --- a/text_collector_examples/apt.sh +++ b/text_collector_examples/apt.sh @@ -5,7 +5,9 @@ # Author: Ben Kochie upgrades="$(/usr/bin/apt-get --just-print upgrade \ - | /usr/bin/awk '/^Inst/ {print $5, $6}' \ + | /usr/bin/awk -F'[()]' \ + '/^Inst/ { sub("^[^ ]+ ", "", $2); sub("\\[", " ", $2); + sub(" ", "", $2); sub("\\]", "", $2); print $2 }' | /usr/bin/sort \ | /usr/bin/uniq -c \ | awk '{ gsub(/\\\\/, "\\\\", $2); gsub(/\"/, "\\\"", $2);