I am trying to grep the exact match line.
grep '^listen' /etc/php-fpm.d/www.conf
listen = /run/php-fpm/www.sock
listen.acl_users = apache,nginx
listen.allowed_clients = 127.0.0.1
I want it to show only the following
listen = /run/php-fpm/www.sock
not the other lines. how to do that?.
You may use this grep
to make sure there is at least one space or tab character or =
after matching listen
at start:
grep '^listen[=[:blank:]]' file
or do string comparison of first field using awk
:
awk -F '[=[:blank:]]+' '$1 == "listen"' file
Use grep -P
like so, with \s
meaning whitespace:
grep -P '^listen\s' /etc/php-fpm.d/www.conf
Here, grep
uses the following option:
-P
: Use Perl regexes.
SEE ALSO:
grep
manual
perlre - Perl regular expressions
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.