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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SED Search Pattern and Replace with the Pattern racbern Shell Programming and Scripting 4 03-15-2008 01:59 AM
Search Mulitiple String pattern in a file krishnan_6015@y Shell Programming and Scripting 2 11-23-2007 12:03 AM
How to search a pattern inside a zipped file ie (.gz file) with out unzipping it senraj01 Shell Programming and Scripting 2 04-26-2006 01:32 AM
Search a file for pattern? davjoyce UNIX for Dummies Questions & Answers 2 03-07-2006 02:07 PM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 11:41 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 151
File search for pattern - script

Hi All,

I have two directories as

1) mi/job -> job1.sh, job2.sh, job3.sh
2) mi/sysin -> sysin1, sysin2, sysin3,sysin4

I want to wrrite a script such that it should accept two parameters as directory paths.

$ myscript mi/sysin mi/job.

The script should be able to scan all files in the 2nd parameter mi/job for occurence of files existing in the 1st parameter.
i.e it should scan job1.sh, job2.sh,... for occurences of sysin1, sysin2,...

It should print these occurences.

Also, it should search in the 2nd parameter for the occurence of another script name, except for the script itself. i.e it should check for occurence of sysin1 in sysin2, sysin3,... [all files in the same directory except sysin1[

It should print all these occurences too.

Thanks,
Rahul.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-15-2007
Moderator
 

Join Date: Feb 2007
Posts: 1,975
Hi,

Can you show us what you've gotten so far?

Regards
Reply With Quote
  #3 (permalink)  
Old 02-15-2007
Registered User
 

Join Date: Aug 2005
Location: Bangalore
Posts: 196
I am not very much clear about what you are looking for. do you want to find the filenames(mi/sysin files) present in your shell programs(mi/job)???
However on a grander basis you could try to start this way.

ls $1 >output
for filename in `cat output`
do

grep $filename $2 >temp.$$

###whatever you want to do here



done
Reply With Quote
  #4 (permalink)  
Old 02-16-2007
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 151
I guess this should work...I'm trying with passing different arguments. Let's see.

Code:
rm -f Output.txt
touch Output.txt

rm -f FinalOutput.txt
touch FinalOutput.txt

ls $1 | cut -d" " -f1 | while read line
do
   find $1 –exec grep –r  - -exclude=$1 $line {} ?; -print >> Output.txt
   b=`grep -i "$line" Output.txt`
   if [ "$b" != "" ]; then
        echo "Value is present in the file"
   else
       #echo "Value is not present in the file"
       echo $line >> FinalOutput.txt
   fi
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0