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
lorcan
August 8, 2007, 1:15am
2
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
anon57720281:
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
lorcan
August 9, 2007, 1:09am
5
So are you trying to match either of the strings in your file, or do you want both of the strings to be present.
FOOGLE
August 9, 2007, 1:26am
6
try
/usr/xpg4/bin/grep -e 'string1|string2'
foogle knows what he's doing
waiq
August 9, 2007, 5:02am
8
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