I'm trying to add a prefix to all output of the following command:
sudo apt update && sudo apt -y upgrade
I've been scouring the internet and it seem there are 2 outputs to handle. STDOUT, and STDERR.
I've found the following:
sudo apt update && sudo apt -y upgrade > >(sed "s/^/[prefix1]/") 2> >(sed "s/^/[prefix2]/" >&2)
Which seems to redirect stdout and stderr and append the [prefix1] and [prefix2], however, there are still some output lines which do not have a prefix, and I'm wondering what I'm missing?
The output looks like this:
Hit:1 http://ca.archive.ubuntu.com/ubuntu mantic InRelease
Hit:2 http://ca.archive.ubuntu.com/ubuntu mantic-updates InRelease
Hit:3 http://ca.archive.ubuntu.com/ubuntu mantic-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu mantic-security InRelease
Hit:5 https://apt.postgresql.org/pub/repos/apt mantic-pgdg InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
[prefix2]
[prefix2]WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
[prefix2]
[prefix1]Reading package lists...
[prefix1]Building dependency tree...
[prefix1]Reading state information...
[prefix1]Calculating upgrade...
[prefix1]0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
How can I prefix the lines which start with HIT:, Reading, Building?