Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Let's say I gave you the following text:

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

What I want to do is create a regular expression that can parse text like this looking for two or more words on the same line. For example, if I was looking for a SELinux boolean that covered "ftp" AND "home" on the same line, I would currently do the following:

getsebool -a | grep -i ftp | grep -i home

However, I am looking for a regular expression that does the same thing. Specifically, find all of the words in any order on a line...

share|improve this question
2  
Perhaps this question is better suited for Theoretical Computer Science. IMO, a pipeline of multiple greps is going to be much more concise than the single regex that captures the same thing. For two words, the regex might be doable, but in the general case, the length of the regex will explode combinatorially. –  Steven Monday Mar 25 '12 at 15:42

2 Answers 2

up vote 4 down vote accepted

Maybe something like

getsebool -a | egrep -i ".*(ftp.*home|home.*ftp).*"

would work for you?

share|improve this answer
1  
The leading and trailing .* are superfluous –  Brian Mar 27 '12 at 16:57

You could also use awk instead. With awk you can easily use Boolean constructs.

getsebool -a | awk '/ftp/ && /home/ {print}'
# case insensitive
getsebool -a | awk 'tolower($0)~/ftp/ && tolower($0)~/home/ {print}'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.