Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shell : Test on Strings ???

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I would like to know how to compare a string with another one ending with a particular substring ...For exemple
word1 = dfgABC
word2 = dfgvdhqdhABC
word3 = kdhqkdhqkdhkqsd

What i want is to test if word1 or Word2 ...is ending with ABC..I mean word = *ABC where ..
In my script I would like to verify this before going on ..how to proceed ?

 
What is wrong using "*ABX" ? "Long live king Moshiach !"
 
What is wrong using "*ABC" ? "Long live king Moshiach !"
 
Hi, what about this:

Code:
word1=dfgABC
word2=dfgvdhqdhABC
word3=kdhqkdhqkdhkqsd

len1=`expr "$word1" : ".*"`
len2=`expr "$word2" : ".*"`
len3=`expr "$word3" : ".*"`

string1=`echo $word1 | cut -c\`expr ${len1} - 2\`-${len1}`
string2=`echo $word2 | cut -c\`expr ${len2} - 2\`-${len2}`
string3=`echo $word3 | cut -c\`expr ${len3} - 2\`-${len3}`

if [ "${string1}" = "${string2}" ]
then ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top