Trying to use `dpkg` and `egrep` commands to list packages whose names starts with `q`. Already tried:

```
dpkg -l | egrep -l q
dpkg -l | egrep -l ^q
dpkg -l | egrep q
dpkg -l | grep q

```

What is going wrong?
['https://unix.stackexchange.com/questions/546926', 'https://unix.stackexchange.com', 'https://unix.stackexchange.com/users/377372/']
Use `--get-selections` instead of `-l` option:

```
dpkg --get-selections |grep ^q

```

Or using `awk` to change the column order:

```
dpkg -l |awk '{print $2 , $3 "\t\t" $1}' | grep ^q

```
The regular expressions for egrep do not match the expected output of `dpkg -l`. If you wish to keep the same output format as `dpkg -l`, which includes the sate of the package, the version and a description, then the regular expression needs to be changed to match the expected format: three characters at the start of the line (describing the state of the package on the system) and a space before the package name.

In the expression `^... [qQ]`, `^` indicates to match from the start of a line, `...` says to match any three characters followed by a space, then `q` matches packages that start with either an upper or lower case "q" (packages should only be lowercase on Ubuntu but there may be custom packages that do not follow these rules).

```bsh
$ dpkg -l | egrep '^... [qQ]'
ii  qdbus                                         4:4.8.7+dfsg-7ubuntu1                        amd64        Qt 4 D-Bus tool
ii  qemu-block-extra:amd64                        1:2.11+dfsg-1ubuntu7.19                      amd64        extra block backend modules for qemu-system and qemu-utils
...

```