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.

Hi,

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

Regards

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

I guess this should work...I'm trying with passing different arguments. Let's see.


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