# grep for 2 string with an "AND" operator

**URL:** <https://community.unix.com/t/grep-for-2-string-with-an-and-operator/302960>\
**Category:** UNIX for Advanced & Expert Users\
**Created:** [January 18, 2012, 6:03am UTC](https://community.unix.com/t/grep-for-2-string-with-an-and-operator/302960 "2012-01-18T06:03:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cokedude](https://community.unix.com/letter_avatar/cokedude/32/5_5575768a8748004e209b776fc1b2916d.png) [@cokedude](https://community.unix.com/u/cokedude)\
**Post date:** [January 18, 2012, 6:03am UTC](https://community.unix.com/t/grep-for-2-string-with-an-and-operator/302960/1 "2012-01-18T06:03:41Z")

</div>

How can you grep for 2 string with an "AND" operator? I know you can always pipe your first grep through another grep but I was hoping there is a way to do that with an "AND" operator.

---

<div class="post-metadata">

**Author:** ![venkatareddy](https://community.unix.com/letter_avatar/venkatareddy/32/5_5575768a8748004e209b776fc1b2916d.png) [@venkatareddy](https://community.unix.com/u/venkatareddy)\
**Post date:** [January 18, 2012, 6:08am UTC](https://community.unix.com/t/grep-for-2-string-with-an-and-operator/302960/2 "2012-01-18T06:08:57Z")

</div>

Hi,  
you can use this way with egrep

egrep "word1.\*word2" file

thanks,  
venkat

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [January 18, 2012, 9:34pm UTC](https://community.unix.com/t/grep-for-2-string-with-an-and-operator/302960/3 "2012-01-18T21:34:04Z")

</div>

awk does it with && (boolean and)

```nohighlight
awk '/pattern1/ && /pattern2/' filename

```

---

<div class="post-metadata">

**Author:** ![drl](https://community.unix.com/user_avatar/community.unix.com/drl/32/542_2.png) [@drl](https://community.unix.com/u/drl)\
**Post date:** [January 20, 2012, 12:05pm UTC](https://community.unix.com/t/grep-for-2-string-with-an-and-operator/302960/4 "2012-01-20T12:05:41Z")

</div>

Hi.

See also glark:

> [@](#):
>
> A replacement for (or supplement to) the grep family, glark offers: Perl compatible regular expressions, highlighting of matches, context around matches, complex expressions (``and'' and ``or''), and automatic exclusion of non-text files.
> 
> [incava.org](http://www.incava.org/projects/glark/)

Some examples can be seen here with a search for glark, including an example at [grep command with AND condition](http://www.unix.com/shell-programming-scripting/128435-grep-command-condition.html) , post #4.

Best wishes ... cheers, drl
