How to avoid grep warning messages


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to avoid grep warning messages
# 1  
Old 03-18-2009
Error How to avoid grep warning messages

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
# 2  
Old 03-18-2009
Redirect the output of stderr to /dev/null:

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

# 3  
Old 03-18-2009
Thanks Franklin. It works fine..

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

Thanks,
Parkkavan
# 4  
Old 03-18-2009
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.
# 5  
Old 03-18-2009
Thanks wireonfire for the explanation. :-)

Regards,
Parkkavan
# 6  
Old 03-18-2009
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:

Code:
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.

Last edited by Mumford; 03-18-2009 at 05:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can't grep for warning in log file

Hi Can't see what I am doing wrong here: Trying to view a log file and grep for WARNING but keep getting the following error: $ view datasource.log | grep WARN Vim: Warning: Output is not to a terminal WARNING: JMX not enabled. To enable, specify rmi-client-port and rmi-registry-port... (2 Replies)
Discussion started by: simpsa27
2 Replies

2. Shell Programming and Scripting

How to print warning messages on console when we use exec command?

I am having script in which for logging I am using exec command. I am calling another script/program through this script which is designed for another user id. So, After running script it is giving warning message as "This program has been designed for another user id. Please press Enter to... (6 Replies)
Discussion started by: VSom007
6 Replies

3. UNIX for Dummies Questions & Answers

UNIX command to skip any warning messages and continue job execution

Hello All, Good day! This is my first UNIX post. :D Anyways, I would like to seek help from you guys if you know of any UNIX command that will skip a warning message once it is encountered but continue to run the execution. Ok here's the situation in general: An encypted file is sent to... (2 Replies)
Discussion started by: jennah_rekka
2 Replies

4. Solaris

[kern.warning] messages in /var/adm/messages

Hi Having looked through the log file /var/adm/messages i've noticed these kernel warning messages and i don't know what they mean: !-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> cpudrv: NOTICE: cpu_acpi: _TSS package not found. cpudrv: WARNING:... (1 Reply)
Discussion started by: jpg.2009
1 Replies

5. Solaris

Help understanding [daemon.warning] messages in /var/adm/messages

Hi I've been using solaris for a few days now. During the install process i had some problems configuring my nic as i needed to install a third-party driver, which i got from a a linked site from the Sun Device Detector tool a ran prior to installing. I got it working eventually, but i'm... (1 Reply)
Discussion started by: jpg.2009
1 Replies

6. Shell Programming and Scripting

display warning messages on command line

I have made a script to print size of a slice if it reaches more then 80% which is working fine no problem in it. I want to add this script in crontab to print this message on command line every half hour if slice size reaches more then 80%. here is the line below i added on crontab 30 *... (2 Replies)
Discussion started by: Danish Shakil
2 Replies

7. Solaris

Info req: /var/adm/messages - Kern.warning - different ID messages

Hi all, where I can find a list and meaning of the ID number (for example ID 353554 kern.warning)? Thanks in advance Pierluigi (1 Reply)
Discussion started by: Petrucci
1 Replies

8. UNIX for Dummies Questions & Answers

grep exact string/ avoid substring search

Hi All, I have 2 programs running by the following names: a_testloop.sh testloop.sh I read these programs names from a file and store each of them into a variable called $program. On the completion of the above programs i should send an email. When i use grep with ps to see if any of... (3 Replies)
Discussion started by: albertashish
3 Replies

9. Shell Programming and Scripting

Redirecting the warning messages.

I have written a Perl module. We know that we have to include the "-w" option in the first line as good programming practise. #! /usr/bin/perl -w Now when i use this,it gives me a number of warnings which are pretty much harmless as the code works perfectly fine without the -w option. Now... (1 Reply)
Discussion started by: keka
1 Replies
Login or Register to Ask a Question