Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Regex in if-then-else statement to match strings Post 302136861 by radoulov on Thursday 20th of September 2007 05:02:11 AM
Old 09-20-2007
Yes, it's globbing, not re's.
For {2,3} with globbing:

Code:
bash 3.2.25(1)$ v=b
bash 3.2.25(1)$ case $v in ([ab][ab]|[ab][ab][ab]) echo OK;;(?) echo KO;;esac
KO
bash 3.2.25(1)$ v=bbb
bash 3.2.25(1)$ case $v in ([ab][ab]|[ab][ab][ab]) echo OK;;(?) echo KO;;esac
OK
bash 3.2.25(1)$ # or:
bash 3.2.25(1)$ shopt -s extglob
bash 3.2.25(1)$ v=b
bash 3.2.25(1)$ case $v in ([ab][ab]?([ab])) echo OK;;(?) echo KO;;esac
KO
bash 3.2.25(1)$ v=bb
bash 3.2.25(1)$ case $v in ([ab][ab]?([ab])) echo OK;;(?) echo KO;;esac
OK

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regex to match basename

Hi Can somebody please help me know how do i match the basename using a regular expression using posix standard in shell script suppose i want to match /u01/Sybase/data/master.dbf the result should be master.dbf as i want to match everything after the last / regards (8 Replies)
Discussion started by: xiamin
8 Replies

2. Shell Programming and Scripting

Regex: Get the word before match

Hi Input: MYTEXT.aa.bb cc.MYTEXT.aa.bb ee.dd.cc.MYTEXT.aa.bb cc.NOTEXT.a.b Output: <empty> cc cc <empty> I would like to use a regex to extract the last word before MYTEXT without the dot (2 Replies)
Discussion started by: chitech
2 Replies

3. Shell Programming and Scripting

If statement with [[ ]] and regex not working as expected

Using BASH: $ if -- ::00" ]]; then echo "true"; else echo "false"; fi false Mike (5 Replies)
Discussion started by: Michael Stora
5 Replies

4. Shell Programming and Scripting

Regex within IF statement in awk

Hello to all, I have: X="string 1-" Y="-string 2" Z="string 1-20-string 2"In the position of the number 20 could be different numbers, but I'm interest only when the number is 15, 20,45 or 70. I want to include an IF within an awk code with a regex in the following way. ... (12 Replies)
Discussion started by: Ophiuchus
12 Replies

5. Shell Programming and Scripting

Only Regex pattern match help

Hi We have a tool to monitor logs in our environment. The tool accepts log pattern match only using regex and I accept I am a n00b in that:confused:. I had been banging my head to make it work without much success and at last had to turn on to my last option to post it here. I had got great... (2 Replies)
Discussion started by: radioactive9
2 Replies

6. Shell Programming and Scripting

Perl - what does this statement mean -Regex

push @MACARRAY, "$+{catalog} $+{machine}\n" if ($info =~ /(?<catalog>catalog).+?(?<machine>\*+)/ms); I am (still) trying to solve problem. Looking around on the server I found this piece of code. Specifically what does "$+{catalog} $+{machine}\n" do ? Thanks in advance (1 Reply)
Discussion started by: popeye
1 Replies

7. Shell Programming and Scripting

Using BASH =~ regex to match multiple strings

I have a scripting problem that I'm trying to solve, whereby I want to match that a string contains either of three strings. I'm thinking this is probably just me not understanding how to craft the appropriate regex. However, here's what I would like to do: ] && do-something more... (10 Replies)
Discussion started by: forrie
10 Replies

8. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

9. Shell Programming and Scripting

Mailq regex match

Hi, # mailq | awk '{match($0, /quota/)} {print $0}' | head -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- 9A6A7DE117E 84309 Sat Sep 30 14:14:50 alerts-noreply+xxxxx=xxx.sg@xxx.xx.xxx (host alt1.gmail-smtp-in.l.google.com said: 452-4.2.2 The email account that you... (2 Replies)
Discussion started by: ashokvpp
2 Replies

10. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies
LIBBASH(7)							  libbash Manual							LIBBASH(7)

NAME
libbash -- A bash shared libraries package. DESCRIPTION
libbash is a package that enables bash dynamic-like shared libraries. Actually its a tool for managing bash scripts whose functions you may want to load and use in scripts of your own. It contains a 'dynamic loader' for the shared libraries ( ldbash(1)), a configuration tool (ldbashconfig(8)), and some libraries. Using ldbash(1) you are able to load loadable bash libraries, such as getopts(1) and hashstash(1). A bash shared library that can be loaded using ldbash(1) must answer 4 requirments: 1. It must be installed in $LIBBASH_PREFIX/lib/bash (default is /usr/lib/bash). 2. It must contain a line that begins with '#EXPORT='. That line will contain (after the '=') a list of functions that the library exports. I.e. all the function that will be usable after loading that library will be listed in that line. 3. It must contain a line that begins with '#REQUIRE='. That line will contain (after the '=') a list of bash libraries that are required for our library. I.e. every bash library that is in use in our bash library must be listed there. 4. The library must be listed (For more information, see ldbashconfig(8)). Basic guidelines for writing library of your own: 1. Be aware, that your library will be actually sourced. So, basically, it should contain (i.e define) only functions. 2. Try to declare all variables intended for internal use as local. 3. Global variables and functions that are intended for internal use (i.e are not defined in '#EXPORT=') should begin with: __<library_name>_ For example, internal function myfoosort of hashstash library should be named as __hashstash_myfoosort This helps to avoid conflicts in global name space when using libraries that come from different vendors. 4. See html manual for full version of this guide. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <ril@ran4.net> SEE ALSO
ldbash(1), ldbashconfig(8), getopts(1), hashstash(1) colors(1) messages(1) urlcoding(1) locks(1) Linux Epoch Linux
All times are GMT -4. The time now is 04:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy