I am trying to use a simulated "and" statement with egrep. Currently I have egrep -i 'name.*policy' which works only if the order of appearance is true. Alternatively, I can egrep -i 'name.*policy|policy.*name' . I want to see if there is a better way to use an "and statement that is not order specific.
Asked
Active
Viewed 148 times
1
-
2There isn't, use your solution or `grep name | grep policy` – ctx Mar 21 '17 at 17:34
-
Sorry yes it is duplicated for the most part. I was hoping to see if there was an improved way to use " egrep -i 'name.*policy' " that would not be order specific. Clearly there is not. – Steve Mar 21 '17 at 18:10
1 Answers
1
grep -P '(?=.*policy)(?=.*name)'
-
Thank you, unfortunately in my version of BSD, the -P option doesn't work. – Steve Mar 21 '17 at 18:08