If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Wildcards KSH

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-05, 10:59
namliam namliam is offline
Registered User
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 421
Wildcards KSH

Uhm, probably a stupid question....

I want to find out if a string is in a variable.
myvar='thisisnamliamsstupidquestion'
if [ "$myvar" like "namliam" ]
would return a true or maybe a 7 as that is the character it is starting.

Just searching (a bit quickly) I am not finding it. Any bright minds out there? As its CoB for me... Hope to find a nice answer in the morning

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 11-25-05, 11:33
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
Wink

hi,
actually I don't know any way for such a string manipulation in ksh. For that it would be better to use perl. But for your pupose I think it could help this:

------------------------------------------------
myvar='thisisnamliamsstupidquestion'
echo $myvar|grep "namliam"
if test $? -eq 0
then
echo "String found"
else
echo "String NOT found"
fi
--------------------------------------------------

I hope it works for you.
ducasio
Reply With Quote
  #3 (permalink)  
Old 11-28-05, 01:34
namliam namliam is offline
Registered User
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 421
Thanks

Tho I found another way of dealing with my problem using AWK, not the nicest of solutions, but it works.... for now.

Also I put this to a function, so if ever things change I can do it all over without problems.

In this particular case I would be testing 5 or 6 options. I thought of doing the grep thing... But for 5 to 6 options... A bit of a "nail biter", so I went with the AWK (one line) function.

Thanks again.
Reply With Quote
  #4 (permalink)  
Old 11-29-05, 11:08
ducasio ducasio is offline
Registered User
 
Join Date: Aug 2004
Location: Rome, Italy
Posts: 81
Talking

Very good then.

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On