LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2008, 10:21 AM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
pattern match : korn shell


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.
 
Old 12-31-2008, 12:08 PM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi.

One way:
Code:
#!/usr/bin/env ksh

# @(#) s1       Demonstrate globbing [file-like] pattern matching.

echo
export LC_ALL=C
echo "Environment: LC_ALL = $LC_ALL"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1)
echo

for s in abcdef abc
do
  if [[ "$s" = a??d?f ]]
  then
    echo " String :$s: passes"
  else
    echo " FAILED to match :$s:"
  fi
done

exit 0
Producing:
Code:
% ./s1

Environment: LC_ALL = C
(Versions displayed with local utility "version")
Linux 2.6.11-x1
PD KSH v5.2.14 99/07/13.2

 String :abcdef: passes
 FAILED to match :abc:
Best wishes ... cheers, makyo
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
How to delete the file using pattern match? nishanthhampali Programming 3 04-16-2008 12:50 PM
simple pattern match with awk, sed alenD Linux - Newbie 10 03-10-2008 02:31 PM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM
Procmail: match pattern then pass to shell script essdeeay Linux - Software 1 11-08-2004 02:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration