pattern match

Hi all,

I have small comparison to make.

I have say two strings,

StringA="abcdefg"
StringB="abc"

I would like to have a statement which checks if the string contains the below pattern.

"a _ _ d _ f _"

StringA passes the test, where as StringB fails the test

How can I make such comparison, without using grep or sed.

Hi,

try:

command:

[[ "abc" =~ "a..d.f." ]] && echo hit || echo miss

output:

miss

command:

[[ "abcdefg" =~ "a..d.f." ]] && echo hit || echo miss

output:

hit

HTH Chris

Thanks for the quick reply,

I am getting the following error though,

I am using korn shell, if at all it helps

The "=~" operator is a feature of bash 3.0 of higher.
In ksh you could use something like:

command:

grep -q "a..d.f." <<< "abcdefg" 
[[ $? = 0 ]] && echo hit || echo miss

output:

hit