假设我给了你以下文本:
allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> on
httpd_execmem --> off
httpd_read_user_content --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
我想要做的是创建一个正则表达式,可以解析此类文本,查找同一行上的两个或多个单词。例如,如果我要查找同一行上涵盖“ftp”和“home”的 SELinux 布尔值,我目前会执行以下操作:
getsebool -a | grep -i ftp | grep -i home
但是,我正在寻找一个可以做同样事情的正则表达式。具体来说,就是在一行中以任意顺序找到所有单词...
答案1
也许类似
getsebool -a | egrep -i ".*(ftp.*home|home.*ftp).*"
对你有用吗?
答案2
您也可以改用 awk。使用 awk,您可以轻松使用布尔构造。
getsebool -a | awk '/ftp/ && /home/ {print}'
# case insensitive
getsebool -a | awk 'tolower($0)~/ftp/ && tolower($0)~/home/ {print}'