help needed for a script!!

Hi!! Im new to shell scripting. I have an important assignment to complete in my company tomorrow. Please help me. I have to write an interactive script which does the following thing:

There is a file named ""rules"in a folder say /home/f1/ . This file contains text in the form:

123
345
456
678
...

I have to search for all the patterns in another folder say /home/f2 which contains various templates say temp1, temp2, temp3 etc. Each of this template has a content which looks like:
********
********

  • rules 123
    -rules 345
    ^^^^
    ^^
    etc.

All the contents of rules may or may not be included in the temp files.

I have to find what all templates contain which files
for eg: rule 123: temp1, temp3, temp4
rule 345: temp2, temp5

The file rules has around 300 rules and the number of templates is around 100.

Hi,

#!/bin/sh

while read rule_line
do
        search="rules "$rule_line
        echo $search
        grep -w "$search" /home/f2/temp*   | awk -F':'  '{print($1)}'
        echo ""

done < /home/f1/rules

thanks pravin!!
but can u tell me will this work:

grep -f /home/f1/rule.txt -i -n /home/f2/temp*

actually im not sure whether the version of linux installed in my company supports the grep -f option or not. can u tell me is the option -f available in older versions of linux and solaris??

Hi Rahul,

This will work. But if you want exact match e.g. rules 123 in temp file then you have to
use -w option.

Thanks
Pravin

Thank u very much pravin!! I just hope that any of the two methods work tomorrow. :slight_smile:

The -f option is standard; the -w option isn't.