I want to see how many packages from a list are not installed. I use archlinux, so I use pacman -Q to determine if a package is installed. If it is not installed, it returns a message like: "error: package 'package-name' was not found".
I thought I could use grep -c 'error'
like this:
pacman -Q autoconf automake binutils bison fakeroot flex gcc libtool m4 make patch pkg-config | grep -c 'error'
But for me it returns:
error: package 'bison' was not found
error: package 'pkg-config' was not found
0
It returns 0, but I would like it to return 2. Even with awk it doesn't work:
pacman -Q autoconf automake binutils bison fakeroot flex gcc libtool m4 make patch pkg-config | awk '/error: / {count++} END {print count}'
For me, this returns:
error: package 'bison' was not found
error: package 'pkg-config' was not found
So my guess is that variable count
doesn't even have a value since it doesn't get printed. I also tried wc -l
, but that doesn't work, it just returns 0 for me.
What is the correct way to print the number of not-installed packages?
EDIT: I noticed when I do:
pacman -Q autoconf automake binutils bison fakeroot flex gcc libtool m4 make patch pkg-config > tempfile
cat tempfile
The two rows containing the error message are not added to tempfile
(the rest of the command output does). Thought this might help solving this problem.