The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
diaplaying the grep result rag84dec Shell Programming and Scripting 1 03-27-2008 02:37 AM
append a string to a grep result melanie_pfefer Shell Programming and Scripting 8 03-19-2008 07:19 AM
grep to handle a 0 result ocelot UNIX for Dummies Questions & Answers 6 02-05-2007 11:19 AM
To have a numeric result from grep Hak Dee UNIX for Dummies Questions & Answers 2 08-07-2006 08:26 AM
is there any why to get the number of line in grep result ? umen UNIX for Dummies Questions & Answers 1 03-16-2006 09:56 AM

Closed Thread
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
  #1 (permalink)  
Old 05-04-2008
mmdawg mmdawg is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
How to negate grep result?

Here is my script so far:

set dirs = ` find . -name "message.jar" 2> /dev/null | cut -d "/" -f 2 ` | uniq
foreach dir ( $dirs )
if (grep $dir/* someText==null) --> how do I write this in script?
print $dir
end
end
  #2 (permalink)  
Old 05-04-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,441
You should take a look over man find
Tips: Find directory that contain the file message.jar

Code:
find /usr -type f -name "message.jar" -exec dirname {} \;

Once you read the manual you will understand how to fix the loop.

Success
  #3 (permalink)  
Old 05-05-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

It looks like you are using the csh family and you wish to know how to run a command and test the exit status in an if. Most people agree that members of the csh family are not good for scripting because of technical drawbacks and flaws. The Bourne shell family is considered superior for scripting.

However, if you must use csh, you can use braces to obtain the exit status of a command:

Code:
#!/bin/csh

# @(#) s2       Demonstrate csh braces: run command, test exit status.

# Create a scratch file if one does not exist.
touch t1

echo
if ( { ls t1 } ) then
        echo " command ls succeeded."
else
        echo " command ls FAILED."
endif

# Remove file.
rm t1

echo
if ( { ls t1 } ) then
        echo " command ls succeeded."
else
        echo " command ls FAILED."
endif

exit $status

Producing:

Code:
% ./s2

t1
 command ls succeeded.

ls: t1: No such file or directory
 command ls FAILED.

Another method is to run the command outside the if, and set a variable to the exit status variable $status. That is something you can try on your own. See man csh for details -- it's long, but if you continue to use csh, you should know about the features ... cheers, drl
  #4 (permalink)  
Old 05-05-2008
mmdawg mmdawg is offline
Registered User
  
 

Join Date: May 2008
Posts: 3
Hi drl,
I am not bound to csh, I can use ksh if necessary. Would using ksh make this any easier?
  #5 (permalink)  
Old 05-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
ksh is Bourne-compatible, so yes, that would be recommended. It's not like this is hard to do in either, just that csh is more likely to limit your future options for developing the script further if you stick with it.
Closed Thread

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 04:01 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