logical AND
How can we try to grep and egrep on two words i.e. both words should exists in the line.
something like Code:
egrep "Word1&Word2" |
Code:
egrep Word1 file | egrep Word2 edit: If you need a single statement, try this. Code:
egrep '(Word1.*Word2|Word2.*Word1)' file |
I mean by using single egrep... looks like logical OR is working
Code:
egrep "Word1|Word2" Similarly also looking for grep command as well |
Quote:
grep uses regexes, not logical statements. Regexes give you some logical options, but those options are to express alternatives in a pattern. "And" is implied unless "|" is used, but what you're talking about is parallel analysis rather than a single expression, though it can be made to work in this simple example. ta0kira PS Note that "|" itself is "xor", meaning that a position is filled by one or the other, but not both. If you use "*" or "+", you just denote repetition of the previous statement, which is entirely arbitrary. |
Try the -P (treat as perl regex) option
ls | grep -P word1.*word2 |
All times are GMT -5. The time now is 09:10 PM. |