The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
#!/bin/sh script fails at StringA | tr "[x]" "[y]" by_tg UNIX for Dummies Questions & Answers 3 02-22-2008 09:17 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
split the string "Setview: arv-temp-view" amitrajvarma Shell Programming and Scripting 2 10-11-2007 02:14 AM
grep/cat/more -- search in a txt file and display content from a specific "keyword" I-1 UNIX for Dummies Questions & Answers 4 02-21-2007 01:57 AM
Block ";" in input string beilstwh High Level Programming 10 06-21-2006 12:02 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-05-2008
Registered User
 

Join Date: Jul 2007
Posts: 8
search excat string in another string (grep "fails")

hello,

i have an statement which i have to correct because it shows the wrong result.

i want to search an excat string in another string, command "grep" shows the wrong result:

example:

STRINGS="string1 string2 string3"
search_string="string"

incorrect:
if [ `echo "${STRINGS}" | grep "${search_string}" > /dev/null 2>/dev/null; \
echo $?` -gt 0 ]
then
echo "not found"
fi

my solution will be a "for statement":
exists="N"
for string in ${STRINGS}
do
if [ "${string}" = "${search_string}" ]
then
exists="J"
break
fi
done
echo $exists

is there any solution with one command. i will use in a shell script, also it possible to use perl for this but my experience in perl is very small ...

regards
Reply With Quote
Google The UNIX and Linux Forums
Forum Sponsor
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:59 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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0