The man page for grep in describing -w says 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. That means that non-word characters (including the spaces around the word) as well as the start of line or end of line will match.
If you have a file with the following contents:
Code:
Apache:
./configure --with-layout=Apache --prefix=/usr/local/apache2 --enable-rule=SHARED_CORE --enable-so --enable-ssl --enable-rewrite --with-ssl=/usr/include
make
make install
Restore from backups:
/etc/rc.d/rc.httpd
/etc/logrotate.d/httpd
/usr/local/apache2/conf (including certs)
/usr/local/apache2/cgi-bin
/usr/local/apache2/modules
/usr/local/apache2/passwd
Here are some examples since they'll show it better than I could explain it:
Code:
$ grep -iEn 'apache' test.txt
1:Apache:
2:./configure --with-layout=Apache --prefix=/usr/local/apache2 --enable-rule=SHARED_CORE --enable-so --enable-ssl --enable-rewrite --with-ssl=/usr/include
8: /usr/local/apache2/conf (including certs)
9: /usr/local/apache2/cgi-bin
10: /usr/local/apache2/modules
11: /usr/local/apache2/passwd
Code:
$ grep -iEn '\<apache\>' test.txt
1:Apache:
2:./configure --with-layout=Apache --prefix=/usr/local/apache2 --enable-rule=SHARED_CORE --enable-so --enable-ssl --enable-rewrite --with-ssl=/usr/include
Code:
$ grep -iEn '\bapache\b' test.txt
1:Apache:
2:./configure --with-layout=Apache --prefix=/usr/local/apache2 --enable-rule=SHARED_CORE --enable-so --enable-ssl --enable-rewrite --with-ssl=/usr/include
Code:
$ grep -iEn '\bapache\B' test.txt
2:./configure --with-layout=Apache --prefix=/usr/local/apache2 --enable-rule=SHARED_CORE --enable-so --enable-ssl --enable-rewrite --with-ssl=/usr/include
8: /usr/local/apache2/conf (including certs)
9: /usr/local/apache2/cgi-bin
10: /usr/local/apache2/modules
11: /usr/local/apache2/passwd
Hope that helps...