something like this should work and I'm sure it can be smarter. dpkg -l > packages.list cat packages.list | while read a b c d ; do echo $b; done