# greping out multiple words

**URL:** <https://community.unix.com/t/greping-out-multiple-words/164411>\
**Category:** Shell Programming and Scripting\
**Created:** [August 20, 2006, 4:52am UTC](https://community.unix.com/t/greping-out-multiple-words/164411 "2006-08-20T04:52:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [August 20, 2006, 4:52am UTC](https://community.unix.com/t/greping-out-multiple-words/164411/1 "2006-08-20T04:52:38Z")

</div>

now i have a lot of words i need to grep out of a certain line but i have to keep typing this:

ex

ls -l | grep -v this | grep -v that | grep -v those | grep -v them .....

i mean, it goes on like that. there has to be a way to grep all those words without having to specify that "grep -v"

does anyone know how to do this?

---

<div class="post-metadata">

**Author:** ![vino](https://community.unix.com/user_avatar/community.unix.com/vino/32/156_2.png) [@vino](https://community.unix.com/u/vino)\
**Post date:** [August 20, 2006, 5:07am UTC](https://community.unix.com/t/greping-out-multiple-words/164411/2 "2006-08-20T05:07:30Z")

</div>

> [@terrible](#):
>
> now i have a lot of words i need to grep out of a certain line but i have to keep typing this:
> 
> ex
> 
> ls -l | grep -v this | grep -v that | grep -v those | grep -v them .....
> 
> i mean, it goes on like that. there has to be a way to grep all those words without having to specify that "grep -v"
> 
> does anyone know how to do this?

I dont have access to a unix box right now. But there is a -E flag. Try grep -vE (this|that|those|them)

---

<div class="post-metadata">

**Author:** ![matrixmadhan](https://community.unix.com/letter_avatar/matrixmadhan/32/5_5575768a8748004e209b776fc1b2916d.png) [@matrixmadhan](https://community.unix.com/u/matrixmadhan)\
**Post date:** [August 20, 2006, 5:23am UTC](https://community.unix.com/t/greping-out-multiple-words/164411/3 "2006-08-20T05:23:03Z")

</div>

grep available in /usr/bin/grep doesnt have the -E option

make use of the grep in

```nohighlight
/usr/xpg4/bin/grep -E 'some1|some2' filename

```

---

<div class="post-metadata">

**Author:** ![system](https://community.unix.com/uploads/default/original/2X/c/c7e9e16a595259edafe88615719d5c5dcda035c2.png) [@system](https://community.unix.com/u/system)\
**Post date:** [August 20, 2006, 5:33am UTC](https://community.unix.com/t/greping-out-multiple-words/164411/4 "2006-08-20T05:33:58Z")

</div>

> [@matrixmadhan](#):
>
> grep available in /usr/bin/grep doesnt have the -E option
> 
> make use of the grep in
> 
> ```plaintext
> /usr/xpg4/bin/grep -E 'some1|some2' filename
> 
> ```

thanks guys. but i need to grep out quite more than 2 words. will the above suffice?

---

<div class="post-metadata">

**Author:** ![matrixmadhan](https://community.unix.com/letter_avatar/matrixmadhan/32/5_5575768a8748004e209b776fc1b2916d.png) [@matrixmadhan](https://community.unix.com/u/matrixmadhan)\
**Post date:** [August 20, 2006, 5:41am UTC](https://community.unix.com/t/greping-out-multiple-words/164411/5 "2006-08-20T05:41:21Z")

</div>

yes very much...

just extend the list delimited by '|'

---

<div class="post-metadata">

**Author:** ![udaykishore](https://community.unix.com/letter_avatar/udaykishore/32/5_5575768a8748004e209b776fc1b2916d.png) [@udaykishore](https://community.unix.com/u/udaykishore)\
**Post date:** [August 20, 2006, 2:58pm UTC](https://community.unix.com/t/greping-out-multiple-words/164411/6 "2006-08-20T14:58:34Z")

</div>

To grep multiple words in file, u can use egrep.

/uday\> egrep 'word1|word2|word3|word4' filename

Uday
