![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to negate grep result? | mmdawg | Shell Programming and Scripting | 4 | 05-05-2008 08:24 AM |
| diaplaying the grep result | rag84dec | Shell Programming and Scripting | 1 | 03-27-2008 02:37 AM |
| How to handle backslash in grep string | rajbal | UNIX for Advanced & Expert Users | 6 | 06-18-2007 08:22 PM |
| How ro handle backslash character in grep? | rajbal | Shell Programming and Scripting | 1 | 06-18-2007 08:19 PM |
| To have a numeric result from grep | Hak Dee | UNIX for Dummies Questions & Answers | 2 | 08-07-2006 07:26 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
grep to handle a 0 result
Hi guys,
I have the following grep command in a script to search through a file for a string and return its count, and it works fine for when the string exists: grep "string" file.txt | wc However, sometimes the result will be 0 and I want the script to take this as the result. Right now it is just dumping out with a "child process exited abnormally" How can I get around this so that if the result is 0 then the script doesnt dump out and takes the result as 0? thanks |
|
||||
|
I have tried grep -c but that doesnt work either, it keeps on dumping out.
The script is actually a TCL script with embedded UNIX commands. The part its failing on is like so: set td [exec grep -c "InvalidMessage" $logdir/$t | wc -l] (I have assigned the variables logdir and t from before) and i run the script and this occurs: child process exited abnormally while executing "exec grep -c "InvalidMessage" $logdir/$t | wc -l" It happens because there are no "InvalidMessage" strings in the file, but I know this and want the result i.e. 0 to be assigned to td |
|
|||||
|
Quote:
Regards, Tayyab |
![]() |
| Bookmarks |
| Tags |
| unix commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|