Pattern for case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern for case
# 1  
Old 04-23-2009
Pattern for case

Hello Experts,

I need to create a case structure, wherein I must chk the input to match 2 values: PSDEV and PSSIT. I would like to do this using a single pattern.

I ve tried:
Code:
case
    PS['SIT''DEV'])
        echo "here"
        ;;
    *)
        echo "there"
        ;;
esac

Idk exactly how should I write the pattern to match. Should it be something like: PS[\(SIT\)\(DEV\)]

The basic requirement is to chk if the input is one of the valid values and perform something if it is one of them. Pls do tell me if there is a more efficient way to achieve this than "case"

Thank You.

Regards,
HKansal
# 2  
Old 04-23-2009
I would keep it simple and just use:
Code:
  PSSIT | PSDEV )

# 3  
Old 04-23-2009
another way - others may not like it:
Code:
#!/bin/ksh

pat='PS'
if [[ "${pat}" = @(PS(DEV|SIT)) ]]; then
   echo 'here'
else
   echo 'there'
fi

# 4  
Old 04-23-2009
partially solved

Hello,

Thanks for the helpSmilie

For the time being I would use what Tony said.

Now this is what I like about this place, vgersh99 has given me a new thing to learn, ty.
@vgersh99: could you please explain the condition evaluated by if.. what is it that "pat" is actually being compared to?

Although I've got 1 solution but I am reluctant in marking the thread as solved as I still want to know the way I wanted to do itSmilie. Just expecting more out of everything.

Thank You.

Regards,
HKansal
# 5  
Old 04-23-2009
if you do 'man ksh' and search for 'File Name generation':
Code:
     A pattern-list is a list of one or more  patterns  separated
     from  each  other with a |. Composite patterns can be formed
     with one or more of the following:

     ?(pattern-list)
           Optionally matches any one of the given patterns.

     *(pattern-list)
           Matches zero or more occurrences  of  the  given  pat-
           terns.

     +(pattern-list)
           Matches one or more occurrences of the given patterns.

     @(pattern-list)
           Matches exactly one of the given patterns.

     !(pattern-list)
           Matches anything, except one of the given patterns.

# 6  
Old 06-11-2009
MySQL Final Script

Hello,

I have posted the final script under the initial thread :here:

Thank You.

Regards,
HKansal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching for pattern in variable using case statements

i would like to search a variable for a pattern, without having make any calls to external tools. i have a code like this: COUNTPRO2="gine is very bad vine is pretty good" case "${COUNTPRO2}" in *vine*) factor=${COUNTPRO2} echo $factor ;; esac If the variable contains... (7 Replies)
Discussion started by: SkySmart
7 Replies

2. Shell Programming and Scripting

Convert to lower case based on pattern

Hi Gurus, I am trying to convert some lines in a file based on the patter.Below is an example. Text after cn= and uid: should be converted to lower case. Input: dn: cn=XXX,ou=111,dc=222,dc=333,dc=444 uid: XXX userPassword:: aAbVCeDr dn: cn=XYZ,ou=111,dc=222,dc=333,dc=444 uid: XYZ... (5 Replies)
Discussion started by: Samingla
5 Replies

3. Shell Programming and Scripting

Script to find duplicate pattern in a file irrespective of case

We have a configuration file in Unix. In that we have entries like below. if it ends with ":", then it is the end of record. We need to find our if there is any duplicate entries like ABCD irrespective of the case. ABCD:\ :conn.retry.stwait=00.00.30:\ :sess.pnode.max=255:\ ... (9 Replies)
Discussion started by: johnjs
9 Replies

4. Shell Programming and Scripting

Ignore case in awk while pattern searching

Hi , I have the file where i have to search for the pattern. The pattern may be lower case or upper case or camel case. Basically I want to ignore while searching the pattern in awk. awk '/error|warning/exception/' filename Please help me (3 Replies)
Discussion started by: arukuku
3 Replies

5. Shell Programming and Scripting

File pattern in Case

Hi , I have writen a scipt and passing one Parameter. In the scipt i want verify the parameter patteren using Case statement. exp: sh script.sh 1213 Code: i want verify the paramater values as only number not charater. can you please advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

6. Shell Programming and Scripting

problem in nawk : case insensitive pattern matching

HI, My file contains data something like 034500,5,B5004946544EB185,DEFAULT,0 Now i want to do a pettern match for DEFAULT and remove that particular line from file and transfer the rest contents to temp file.But my req is i want to do case insensitive matching ie DEFAULT / default. I... (4 Replies)
Discussion started by: centurion_13
4 Replies

7. UNIX for Dummies Questions & Answers

Change case of single character in pattern

Using UNIX tools, but not using GAWK (NAWK is OK), is there a more elegant way to achieve this: sed ' s/_a/_A/1 s/_b/_B/1 s/_c/_C/1 rest of alpahabet ' I want to change the case of a single character in each string of a text file. The character will be matched by regex '_' and only... (2 Replies)
Discussion started by: uiop44
2 Replies

8. Shell Programming and Scripting

pattern matching in case statement

I have a file abc.sh which looks like qacc1 ----> down v5c0 check interface v5c1 I want to read this file line by line and perform a certain action if a particular pattern is found in that line. My code so far looks like this: FileName='abc.sh' while read LINE do echo $LINE case... (2 Replies)
Discussion started by: lassimanji
2 Replies

9. Shell Programming and Scripting

problem with CASE pattern matching

I am using ksh on a HP Ux. I have a simple script but am having problem with the case statement:- #!/usr/bin/sh Chl=”SM.APPLE_SWIFT_DV” LoConfirm=”” case $chl in ) LoConfirm=”Using channel at Building 1” echo “test conditon1” echo $LoConfirm;; ) LoConfirm=”Using... (2 Replies)
Discussion started by: gummysweets
2 Replies

10. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies
Login or Register to Ask a Question