4 Answers
4

aptitude supports searching among all packages known to the package management tools, installed or otherwise, using regular expressions, without extraneous output, and can be told how to format its output:

Here's one good way to do get the list of installed packages on a Debian-based system:

dpkg -l | grep ^ii | awk '{print $2}'

The output lines of dpkg -l can be trusted to be sane.
The pattern ^ii will match the lines of installed packages,
and the simple Awk will extract the second column,
the package names (the same names used in apt-get install commands).
Package names cannot contain whitespace,
so this again is a safe operation.