Sponsored Content
Full Discussion: Pattern matching notation
Top Forums Shell Programming and Scripting Pattern matching notation Post 302785369 by amazigh42 on Monday 25th of March 2013 12:56:12 PM
Old 03-25-2013
Quote:
Originally Posted by alister
You omitted the ")" after the pattern.

On an unrelated note, in case you are not aware, the following can be re-written ...

... by combining pattern alternatives with "|".
Code:
        case $3 in
        0[1-9] | [1-2][0-9] | 3[0-1]) ;;
        *) return 1 ;;
        esac

Note that I did not double-quote $3. There's nothing wrong with doing so, but it's not necessary. Double quotes only protect against field splitting and pathname expansion (file globbing), neither of which is performed on the word which follows "case".

Regards,
Alister
Thank you for yours advices.
But look with this magenta pattern. it doesn't work.
Have you an idea why ?


Code:
#!/bin/bash
#########################################################################
valid() {
case "$1" in
        [E,F,Q,P][A,C,S][A,I,V,P][D,R,T,V]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        [PU][IPS][AGS][1-8]) ;;
        ISO[9-10]ORA) ;;
        *) return 1 ;;
        esac

        case "$3" in
        [0-1][0-9]) ;;
        2[0-3]) ;;
        *) return 1 ;;
        esac

        case "$4" in
        [0-5][0-9]) ;;
        *) return 1 ;;
        esac

        case "$5" in
        server) ;;
        exploitation) ;;
        *) return 1 ;;
        esac

        OLDIFS="$IFS"
        IFS="-"
               set -- $1 # $1=YYYY, $2=MM, $3=DD
        IFS="$OLDIFS"

        case "$1" in
        [2-9][0-9][0-9][0-9]) ;;
        *) return 1 ;;
        esac

        case "$2" in
        0[1-9]) ;;
        1[0-2]) ;;
        *) return 1 ;;
        esac

        case "$3" in
        0[1-9] | [1-2][0-9] | 3[0-1]) ;;
        *) return 1 ;;
        esac

        return 0
}
process() {
echo "$1 $2 $3 $4 $5 $6"
}

        if ! valid $1 $2 $3 $4 $5 $6 # Ignore invalid lines
        then
                echo "$1 $2 $3 $4 $5 $6 is invalid"
        else
        process $1 $2 $3 $4 $5 $6
fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies

2. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

3. Shell Programming and Scripting

Convert decimal notation to ANSI point code notation

wondering if anyone has any thoughts to convert the below thru a shell script Convert decimal signalling point notation to ANSI point code notation There is a site that does that conversion but i need to implement the solution in a shell script.....Thoughts.... OS: Solaris 9 ... (4 Replies)
Discussion started by: aavam
4 Replies

4. Shell Programming and Scripting

[DATE] Pattern matching notation

Hello, I want to verify the format date like 2013-03-08 (YYYY-MM-DD) It doesn't work because the pattern matching notation below returns false while the date is right. Can you help me ? Thanks in advance case "$6" in (-0-0 | -1-1 | -1-2 | -1-3) # Nothing, OK ! ;; (*) echo 'Fatal,... (4 Replies)
Discussion started by: amazigh42
4 Replies

5. Shell Programming and Scripting

Pattern matching notation

Hello, I want to simplify two commands into one. 1st command $type_log_$instance.log.$date.0012nd command $type_log.log.$date.tar.gzInto blue brackets, How do I do to replace the pattern by a blank or _$instance ? $type_log?_$instance].log.$date.*Thank you. (13 Replies)
Discussion started by: amazigh42
13 Replies

6. Shell Programming and Scripting

Pattern matching notation

Hello I have two kinds of logs like server.logserver.log.2013-07-27.001i want to create a variable which look like this (with a pipe) log_name=server.(log|log.$YYYY-MM-DD.)But i tried many cases but it didn't work. Is it possible ? If yes, can you help me. (6 Replies)
Discussion started by: amazigh42
6 Replies

7. Shell Programming and Scripting

Perl: scientific notation to decimal notation

hello folks, I have few values in a log which are in scientific notation. I am trying to convert into actual decimal format or integer but couldn't able to convert. Values in scientific notation: 1.1662986666666665E-4 2.0946799999999998E-4 3.0741333333333333E-6 5.599999999999999E-7... (2 Replies)
Discussion started by: scriptscript
2 Replies

8. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

9. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

10. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies
Regexp::Common::balanced(3)				User Contributed Perl Documentation			       Regexp::Common::balanced(3)

NAME
Regexp::Common::balanced -- provide regexes for strings with balanced parenthesized delimiters or arbitrary delimiters. SYNOPSIS
use Regexp::Common qw /balanced/; while (<>) { /$RE{balanced}{-parens=>'()'}/ and print q{balanced parentheses }; } DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface. Do not use this module directly, but load it via Regexp::Common. $RE{balanced}{-parens} Returns a pattern that matches a string that starts with the nominated opening parenthesis or bracket, contains characters and properly nested parenthesized subsequences, and ends in the matching parenthesis. More than one type of parenthesis can be specified: $RE{balanced}{-parens=>'(){}'} in which case all specified parenthesis types must be correctly balanced within the string. Since version 2013030901, $1 will always be set (to the entire matched substring), regardless whether "{-keep}" is used or not. $RE{balanced}{-begin => "begin"}{-end => "end"} Returns a pattern that matches a string that is properly balanced using the begin and end strings as start and end delimiters. Multiple sets of begin and end strings can be given by separating them by "|"s (which can be escaped with a backslash). qr/$RE{balanced}{-begin => "do|if|case"}{-end => "done|fi|esac"}/ will match properly balanced strings that either start with do and end with done, start with if and end with fi, or start with case and end with esac. If -end contains less cases than -begin, the last case of -end is repeated. If it contains more cases than -begin, the extra cases are ignored. If either of -begin or -end isn't given, or is empty, -begin => '(' and -end => ')' are assumed. Since version 2013030901, $1 will always be set (to the entire matched substring), regardless whether "{-keep}" is used or not. Note Since version 2013030901 the pattern will make of the recursive construct "(?-1)", instead of using the problematic "(??{ })" construct. This fixes an problem that was introduced in the 5.17 development track. This also means the pattern is no longer available for Perls older than 5.010. SEE ALSO
Regexp::Common for a general description of how to use this interface. AUTHOR
Damian Conway (damian@conway.org) MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be). BUGS AND IRRITATIONS
Bound to be plenty. For a start, there are many common regexes missing. Send them in to regexp-common@abigail.be. LICENSE and COPYRIGHT This software is Copyright (c) 2001 - 2013, Damian Conway and Abigail. This module is free software, and maybe used under any of the following licenses: 1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT. perl v5.18.2 2013-03-09 Regexp::Common::balanced(3)
All times are GMT -4. The time now is 02:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy