LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-31-2011, 11:49 AM   #1
Pinglu
LQ Newbie
 
Registered: Sep 2011
Posts: 17

Rep: Reputation: Disabled
Regular Expression in IF statement not working in ksh


Hi,

Here is my code,

if [[ "GEORGE T MAY ESTATE OF " = @(ESTATE OF|SUCCESSION DE) ]] ; then
input=`echo "GEORGE ESTATE OF T MAY" | sed -e 's/ESTATE OF//'`
fi



I want to find the pattern which is "ESTATE OF" or "SUCCESSION DE". In the testing code above, I want to go into that if statement, but as the result, it doesn't execute the if statement. I'm wondering how I can let the if statement be true.

Thanks
 
Old 10-31-2011, 01:03 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
How do you know you do not go into the if? There is no output from your example.
 
Old 11-01-2011, 09:56 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code, to preserve formatting and to improve readability.

Your string values are confusing to me. Please explain exactly what you are doing, and give us some examples of the input, the desired output, and the actual output you get, if any.


At first glance, assuming ksh's [[ test and extended globs are the same as in bash, then you can't match substrings this way. "=" only matches whole strings, so you have to formulate the glob to account for that, or else use a "=~" regex match.

Also, depending on your exact goals, it might be possible to simply replace the test with a parameter substitution.

Code:
$ sub="ESTATE OF |SUCCESSION DE "

$ input="GEORGE ESTATE OF T MAY"
$ echo "${input/@($sub)}"
GEORGE T MAY

$ input="GEORGE SUCCESSION DE T MAY"
$ echo "${input/@($sub)}"
GEORGE T MAY
Finally, $(..) is highly recommended over `..`. (The link is for bash, but it's equally true for ksh.)
 
  


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
[SOLVED] Regular expression working fine in JavaScript but not in python madsovenielsen Programming 3 06-24-2010 07:25 PM
[SOLVED] perl regular expression:: take decimal out of statement. knockout_artist Linux - Newbie 4 06-23-2010 02:17 PM
Regular expression doesnt work in an elsif statement? oinker Programming 2 02-04-2010 01:33 PM
Regular Expression + not Working with grep scottwmackey Linux - General 2 06-21-2006 01:31 AM
KSH Scripting case statement..... ']['HeBroken Programming 1 12-10-2004 10:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:51 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