The output of dpkg -l is made for reading: the manual says its format varies to fit the terminal width and is not easily machine-readable. For a script I use dpkg-query and choose the fields myself.
dpkg-query -W (--show) lists packages that match a pattern. By default it prints one line per package: the name and the installed version, separated by a tab. With -f (--showformat) you give a format string, and fields are written as ${Field}:
dpkg-query -W -f='${Package}\t${Version}\n' 'openssh-*'
In the format string a backslash starts an escape: \n is a newline and \t a tab. The manual says the format is output for each listed package, so I add the \n myself. A width is possible after a semicolon, and a negative width left-aligns, which lets me build a tidy table:
dpkg-query -W -f='${Package;-30} ${Version}\n' 'linux-image-*'
The manual also lists some special fields. binary:Package is the name with an architecture qualifier when that is needed to be unambiguous, binary:Synopsis is the short description and db:Status-Abbrev is the three-letter status such as ii. A list of installed packages with their short description:
dpkg-query -W -f='${binary:Package}: ${binary:Synopsis}\n' | less
Another field in the list is Installed-Size. Sorting on it shows the biggest installed packages:
dpkg-query -W -f='${Installed-Size}\t${Package}\n' | sort -n | tail -n 10
I would treat the number as a rough size as dpkg has it recorded. The manual lists the field but I did not look up the unit, so do not copy it into a report as megabytes.
The caveat is the quoting. Use single quotes, otherwise the shell tries to expand ${Package} itself and you get empty output.
Further reading: dpkg-query(1): –show and –showformat