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 Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-05-2007
ocelot ocelot is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
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
  #2 (permalink)  
Old 02-05-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
grep -c 'string' file.txt
  #3 (permalink)  
Old 02-05-2007
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Can you please post your script here? Let us see what exactly you are trying to acheive.
  #4 (permalink)  
Old 02-05-2007
ocelot ocelot is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
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
  #5 (permalink)  
Old 02-05-2007
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
grep -c "string" also gives you the count of lines then why are you still piping the output to wc -l, it'll always give you the output as "1", please remove it and try.
  #6 (permalink)  
Old 02-05-2007
ocelot ocelot is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 31
Hi,

I removed the wc -l as well. That too didnt work and the result kept on dumping out again...

note: The double quotes i have used are correct in this instance, as this is how a UNIX command is executed in TCL
  #7 (permalink)  
Old 02-05-2007
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Quote:
Originally Posted by ocelot
Hi,

I removed the wc -l as well. That too didnt work and the result kept on dumping out again...

note: The double quotes i have used are correct in this instance, as this is how a UNIX command is executed in TCL
See this link: http://wiki.tcl.tk/8489

Regards,
Tayyab
Sponsored Links
Closed Thread

Bookmarks

Tags
unix commands

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 03:47 PM.


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