As per the
Grep documentation:
Quote:
Originally Posted by https://www.gnu.org/software/grep/manual/html_node/Matching-Control.html#index-_002dw
-w
--word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word constituent characters are letters, digits, and the underscore. This option has no effect if -x is also specified.
|
Using -w means the space at the end of the pattern is likely redundant, but also that a port number is not going to work if there is a word character before the colon - as would be the case if the port is preceded by a valid hostname.
Removing the -w option and replacing the space with a \b will prevent longer ports matching and may be sufficient, but - depending on the specific input - might involve false positives (and thus have an incorrect check value and a bug in the script).
There's also several ways the check can probably be simplified/optimized, but not much point going there without example input and details of the context.