The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep and display n lines after the match is found. cv_pan UNIX for Dummies Questions & Answers 3 09-25-2008 11:15 PM
if match found go to a particular line in perl user_prady Shell Programming and Scripting 17 03-31-2008 03:00 PM
Remote login/copy command throwing an error ashish_panpalia UNIX for Dummies Questions & Answers 1 02-12-2008 05:04 AM
sccs get -ek command is throwing err Shivaprasad BS Shell Programming and Scripting 0 01-31-2008 05:49 AM
How do I prevent cron from returning errors on a file not found? goodmis Shell Programming and Scripting 6 02-06-2007 10:14 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-08-2009
cool.aquarian cool.aquarian is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Question How to prevent grep command from throwing a system trap if No match is found.

Hi

How to prevent grep command from throwing a system trap(or returning error status) if No match is found in the specified file(s) ?

Consider this simple shell script:

Code:
#!/usr/bin/ksh
trap 'STATUS=$?;set +x;echo;echo error $STATUS at line nb $LINENO executing :\
   `sed -n "${LINENO}p" $0`;echo;exit $STATUS' ERR
#====== MAIN STARTS=========
cat server* | grep "ABC" > logfile.log
Now if the files server* dont have matching string "ABC", it throws the trap and gets caught, which I dont want to happen.
I want the file logfile.log to be empty if no match is found.
But if, the file server* dont even exist, then I want trap to catch it and show the error.

Please help...
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0