# How to avoid grep warning messages

**URL:** <https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613>\
**Category:** Shell Programming and Scripting\
**Created:** [March 18, 2009, 3:11pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613 "2009-03-18T15:11:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shellscripter](https://community.unix.com/letter_avatar/shellscripter/32/6_22734026db12803ebb3e059622ac3534.png) [@shellscripter](https://community.unix.com/u/shellscripter)\
**Post date:** [March 18, 2009, 3:11pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613/1 "2009-03-18T15:11:00Z")

</div>

Hi All,  
When i try to grep for a patern in an directory, I am getting warning like "No such file or directory". Anyway script is working as expected. but i need to avoid this warning message.  
Pass="`find . -type f | xargs grep 'test result - pass' | wc -l`"  
grep: ./results/6052278-1-717520-HFR\_QFTS\_ALL.\_\_taskid2.isis\_test.Beginning: No such file or directory  
grep: ISIS: No such file or directory  
grep: config: No such file or directory  
grep: load: No such file or directory  
grep: ./results/6052278-1-717520-HFR\_QFTS\_ALL.\_\_taskid2.isis\_test.Beginning: No such file or directory  
grep: interface%2Fbasic: No such file or directory  
grep: pings%2Ftraceroute%2Fcontroller: No such file or directory  
grep: check: No such file or directory

Thanks,  
Parkkavan

---

<div class="post-metadata">

**Author:** ![Franklin52](https://community.unix.com/user_avatar/community.unix.com/franklin52/32/500_2.png) [@Franklin52](https://community.unix.com/u/Franklin52)\
**Post date:** [March 18, 2009, 3:35pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613/2 "2009-03-18T15:35:42Z")

</div>

Redirect the output of stderr to /dev/null:

```nohighlight
find . -type f | xargs grep 'test result - pass' 2>/dev/null | wc -l

```

---

<div class="post-metadata">

**Author:** ![shellscripter](https://community.unix.com/letter_avatar/shellscripter/32/6_22734026db12803ebb3e059622ac3534.png) [@shellscripter](https://community.unix.com/u/shellscripter)\
**Post date:** [March 18, 2009, 3:41pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613/3 "2009-03-18T15:41:21Z")

</div>

Thanks Franklin. It works fine..

Can you tellme "2" mean in 2\>/dev/null.

Thanks,  
Parkkavan

---

<div class="post-metadata">

**Author:** ![wireonfire](https://community.unix.com/letter_avatar/wireonfire/32/6_22734026db12803ebb3e059622ac3534.png) [@wireonfire](https://community.unix.com/u/wireonfire)\
**Post date:** [March 18, 2009, 3:58pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613/4 "2009-03-18T15:58:15Z")

</div>

2 by default is the file pointer for the error messages, 1 is that for stand output. Both go to screen by default. In this case you redirect error to /dev/null so you don't see them.

---

<div class="post-metadata">

**Author:** ![shellscripter](https://community.unix.com/letter_avatar/shellscripter/32/6_22734026db12803ebb3e059622ac3534.png) [@shellscripter](https://community.unix.com/u/shellscripter)\
**Post date:** [March 18, 2009, 4:01pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613/5 "2009-03-18T16:01:20Z")

</div>

Thanks wireonfire for the explanation. 🙂

Regards,  
Parkkavan

---

<div class="post-metadata">

**Author:** ![Mumford](https://community.unix.com/letter_avatar/mumford/32/6_22734026db12803ebb3e059622ac3534.png) [@Mumford](https://community.unix.com/u/Mumford)\
**Post date:** [March 18, 2009, 4:12pm UTC](https://community.unix.com/t/how-to-avoid-grep-warning-messages/235613/6 "2009-03-18T16:12:42Z")

</div>

You're seeing this because the find command passes the filenames it finds as a list of words separated by spaces. The problem is some of the files have spaces in the names. If you're on Linux or otherwise using GNU find & GNU xargs, you can use:

```nohighlight
find . -type f -print0 | xargs -0 grep 'test result - pass' | wc -l

```

'print0' tells find to use \0 as the separator instead of space, and the -0 option to xargs tells it to accept \0 as the separator.
