How can I simplify the script

Hi all,

How can I simplify following script,
Logic is to find two strings (strings are case sensitive) from a file.

if [ `grep -x "$1" "$path"/Hostname/$file_name|wc -l` -eq 1 ]; then
if [`grep -x "$2" "$path"/Hostname/$file_name|wc -l` -eq 1 ]; then
Group=`echo $1_hostname`
fi
fi

Please help me on this.

Regards
Sudhish s. kumar

You can do something like

grep -x "$1" "$path"/Hostname/$file_name >/dev/null 2>&1
rtn1_val=$?
grep -x "$2" "$path"/Hostname/$file_name >/dev/null 2>&1
rtn2_val=$?

if [[ $rtn1_val -eq 0 && $rtn2_val -eq 0 ]]
then
        Group=`echo $1_hostname`
fi

grep -e "($1|$2)"

grep -e "(string1|string2)" /filename

This command is not working

In fact I was looking for some thing like you suggested

Thanks
Regards
Sudhish S. Kumar

So are you trying to match either of the strings in your file, or do you want both of the strings to be present.

try
/usr/xpg4/bin/grep -e 'string1|string2'

foogle knows what he's doing

:b:

I think you need to escape the "|".. So grep -e "string1\|string2" filename should work.

Thanks a lot, both this code are working fine.

egrep "($1|$2)"
grep -e "string1\|string2"

Thanks
Regards
Sudhish S. kumar