Need help grep multiple ports in a file.

I wish to grep for an entry in a file if it contains and does not start with # , Listen 443 or Listen 9443

Below is what helped me get Listen 443 but how can I tweak the below command to also include Listen 9443 port ?

Note: Listen 8443 or Listen 4438 should fail in the grep.

grep -i '^Listen.*443$' /tmp/server.xml | grep -v '#'

grep -w helps find exact word.

Can you please suggest ?


grep -i '^listen\s*443$'

and no extra "grep" command needed

--- Post updated at 14:22 ---


grep -ix 'listen\s*433'
1 Like

Only match 443 or 9443, most simple as ERE (egrep or grep -E)

egrep '^Listen[[:blank:]]+9?443$'

Using a Posix character class rather than a GNU \s

1 Like