# Grep command construction

**URL:** <https://community.unix.com/t/grep-command-construction/343129>\
**Category:** Shell Programming and Scripting\
**Created:** [May 27, 2014, 5:42am UTC](https://community.unix.com/t/grep-command-construction/343129 "2014-05-27T05:42:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [May 27, 2014, 5:42am UTC](https://community.unix.com/t/grep-command-construction/343129/1 "2014-05-27T05:42:52Z")

</div>

Hi,

I have an array variable "arr" that reads string from a file "vari.txt". Thus, the array will be of variable length depending how many entries are present in "vari.txt"

I use a for loop to traverse through the array.

However, i need a grep command to grep for a file "output.txt" and displays all the lines of output.txt except those that are present in the arrar arr.

I know how to traverse an array, `grep -v` and how to grep for multiple strings simultaneously.

Can you help me how could i achieve the grep command that displays all the lines of "output.txt" except those that are present in the arrar arr.

vari.txt (in this sample we have 4 entries, but it can have more or less entries i.e it varies)

```nohighlight
Hello
Yellow
Home
Fellow

```

output.txt

```nohighlight
The grass is Green.
Fellow, The color is Yellow.
I like to see you play.
i rang you up and said HELLO

```

The desired result should be:

```nohighlight
The grass is Green
I like to see you play.

```

---

<div class="post-metadata">

**Author:** ![Scrutinizer](https://community.unix.com/user_avatar/community.unix.com/scrutinizer/32/1216_2.png) [@Scrutinizer](https://community.unix.com/u/Scrutinizer)\
**Post date:** [May 27, 2014, 6:04am UTC](https://community.unix.com/t/grep-command-construction/343129/2 "2014-05-27T06:04:20Z")

</div>

Hi, it could be done without an intermediate shell variable of array, like this:

```nohighlight
grep -viFf vari.txt output.txt

```

Note the "case insensitive" `-i` , otherwise `HELLO` would not match `Hello`

---

<div class="post-metadata">

**Author:** ![mohtashims](https://community.unix.com/letter_avatar/mohtashims/32/6_449c533f586939b6e5f246632a46421f.png) [@mohtashims](https://community.unix.com/u/mohtashims)\
**Post date:** [May 27, 2014, 7:23am UTC](https://community.unix.com/t/grep-command-construction/343129/3 "2014-05-27T07:23:26Z")

</div>

> [@scrutinizer](#):
>
> Hi, it could be done without an intermediate shell variable of array, like this:
> 
> ```plaintext
> grep -viFf vari.txt output.txt
> 
> ```
> 
> Note the "case insensitive" `-i` , otherwise `HELLO` would not match `Hello`

```plaintext
grep -viFf vari.txt output.txt
grep: illegal option -- F
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

```

If i remove -F -f options i do not get the desired output. It displays all entries of output.txt.

```plaintext
SunOS mymac 5.10 Generic_150400-09 sun4v sparc SUNW,SPARC-Enterprise-T5220

```

Please help !!

---

<div class="post-metadata">

**Author:** ![CarloM](https://community.unix.com/letter_avatar/carlom/32/6_449c533f586939b6e5f246632a46421f.png) [@CarloM](https://community.unix.com/u/CarloM)\
**Post date:** [May 27, 2014, 7:45am UTC](https://community.unix.com/t/grep-command-construction/343129/4 "2014-05-27T07:45:05Z")

</div>

Try using `/usr/xpg4/bin/grep` rather than `grep` .
