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 > 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
Couldn't set locale correctly Mr Pink SUN Solaris 7 03-03-2009 08:16 AM
HP-UX will not boot correctly pantas manik HP-UX 1 05-30-2006 02:51 AM
HP-UX will not boot correctly intern UNIX for Dummies Questions & Answers 5 05-24-2006 08:19 AM
Couldn't set locale correctly mattd UNIX for Dummies Questions & Answers 1 02-10-2004 05:11 PM
why the PATH can not be set correctly? yishen UNIX for Dummies Questions & Answers 5 07-23-2002 10:09 PM

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 04-17-2008
sai0899 sai0899 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 1
Question Is grep being used correctly?

My goal is to find files contain the "signal 11" string in a specific directory. I need the file details followed by the string.

I wrote a script to test out and play with Shell command since it's my first time to write a Shell script.

Let me cut the story short...

this command line: if [ 'grep -i "signal 11" $fil' -ne "" ]
returns nothing, but actually in reality, I have couple files contains "signal 11" string.

My question is, why does the script not return a list of files which contains "signal 11"?
Is there anything wrong with my script that you can see?

Thanks in advance!

==========================================

#!/bin/sh
#
RESULT=/disk2/app/applmgr/appltop/cssm_custom/11.5.0/out/W2.out
if [ -f /disk2/app/applmgr/appltop/cssm_custom/11.5.0/out/W2.out ]
then
rm $RESULT
fi
#List all modified files more then 7 days in the Directory
for fil in `find /disk2/app/applmgr/comntop/admin/log/ARDEV_arebdd -type f -mtime +7`
do
#Check if the file contains "signal 11"
#If Yes, print out the file name to the output file.
if [ 'grep -i "signal 11" $fil' -ne "" ]
then
echo "fil = $fil" >> $RESULT
fi
done
===============================================
  #2 (permalink)  
Old 04-17-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
if grep -ic "signal 11" $fil
then
   echo "fil = $fil" >> $RESULT
fi
  #3 (permalink)  
Old 04-18-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
if your grep supports -l (no need to use if/else )
Code:
grep -l  pattern $fil  >>  out
another way
Code:
awk '/pattern/{print FILENAME;exit}' $file >> out
Sponsored Links
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 07:53 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