The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Does Filename Match Pattern msb65 Shell Programming and Scripting 10 12-16-2008 08:00 PM
Pattern match in grep tipi Shell Programming and Scripting 4 08-25-2008 06:56 PM
how do i pattern match a field with awk? someone123 Shell Programming and Scripting 4 06-03-2008 08:08 AM
how to use pattern match with grep rei UNIX for Dummies Questions & Answers 5 01-05-2007 04:33 AM
pattern match and substitution, can you help? frustrated1 Shell Programming and Scripting 4 02-20-2006 08:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-31-2008
tostay2003 tostay2003 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
pattern match

Hi all,

I have small comparison to make.

I have say two strings,
Code:
StringA="abcdefg"
StringB="abc"
I would like to have a statement which checks if the string contains the below pattern.

Code:
"a _ _ d _ f _"
StringA passes the test, where as StringB fails the test

How can I make such comparison, without using grep or sed.
  #2 (permalink)  
Old 12-31-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Hi,

try:

command:
Code:
[[ "abc" =~ "a..d.f." ]] && echo hit || echo miss
output:
Code:
miss
command:
Code:
[[ "abcdefg" =~ "a..d.f." ]] && echo hit || echo miss
output:
Code:
hit
HTH Chris
  #3 (permalink)  
Old 12-31-2008
tostay2003 tostay2003 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
Thanks for the quick reply,

I am getting the following error though,

Quote:
syntax error at line xxx : `=~' unexpected
I am using korn shell, if at all it helps
  #4 (permalink)  
Old 12-31-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
The "=~" operator is a feature of bash 3.0 of higher.
In ksh you could use something like:

command:
Code:
grep -q "a..d.f." <<< "abcdefg" 
[[ $? = 0 ]] && echo hit || echo miss
output:
Code:
hit
Closed Thread

Bookmarks

Tags
grep or

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:52 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0