Grep은 공백 구분 기호를 이해하지 못합니까?

Grep은 공백 구분 기호를 이해하지 못합니까?

다음 예에서는:

apt-file search apache2.conf | grep -E "apache2.conf\b"

산출:

apache2: /etc/apache2/apache2.conf
apache2-doc: /usr/share/doc/apache2-doc/examples/apache2/apache2.conf.gz
dicoweb: /etc/dicoweb/apache2.conf
emboss-explorer: /etc/apache2/conf-available/emboss-explorer.apache2.conf
emboss-explorer: /etc/emboss-explorer/apache2.conf
icinga-cgi: /usr/share/doc/icinga-cgi/examples/apache2.conf
icinga-cgi: /usr/share/icinga/apache2.conf
icinga2-classicui: /etc/icinga2-classicui/apache2.conf
kopano-webapp-apache2: /etc/apache2/conf-available/kopano-webapp-apache2.conf
kopano-webapp-apache2: /etc/kopano/webapp/apache2.conf
lacme: /etc/lacme/apache2.conf
lemonldap-ng-handler: /etc/apache2/sites-available/handler-apache2.conf
libjs-twitter-bootstrap: /usr/share/twitter-bootstrap/apache2.conf
liblemonldap-ng-manager-perl: /etc/apache2/sites-available/manager-apache2.conf
liblemonldap-ng-portal-perl: /etc/apache2/sites-available/portal-apache2.conf
mirmon: /usr/share/doc/mirmon/examples/mirror-apache2.conf
nagios3-cgi: /usr/share/nagios3-cgi/apache2.conf
oar-restful-api: /usr/share/oar/oar-api/apache2.conf
octopussy: /etc/octopussy/apache2.conf
spip: /usr/share/doc/spip/apache2.conf

단어 경계로 이해 하고 다음 줄을 병합해 grep보세요 .\b

apache2-doc: /usr/share/doc/apache2-doc/examples/apache2/apache2.conf.gz

확장() 버전이 있든 없든 -E동일한 결과가 나타납니다 grep.

답변1

단어 경계단어 문자에서 단어가 아닌 문자로의 변환입니다. 이는 단어 문자에서 공백으로의 변환과 다릅니다.

에서 man grep:

단어를 구성하는 문자는 문자, 숫자, 밑줄입니다.

.단어가 아닌 문자는 conf\b" conf뒤에 "가 오기 때문에 일치합니다 ..

답변2

@steeldriver는 이미 \b무슨 일이 일어나고 있는지 설명했습니다.apt-file search, 기본적으로 확장 정규식 옵션을 지원하며 -x경로를 찾을 수 있다고 덧붙였습니다.그리고 apache2.conf:

apt-file search -x 'apache2\.conf$'

다음과 같이 할 수도 있습니다.

apt-file search -x 'apache2\.conf(\s|$)'

공백 으로 끝나 apache2.conf거나 apache2.conf공백이 뒤따르는 경로를 찾으려면 apt-file데이터베이스의 파일에 apache2.conf<whitespace>.

관련 정보