problem with CASE pattern matching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with CASE pattern matching
# 1  
Old 03-18-2008
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
[SM.APPLE_SWIFT_@(AL|DS|DU|DV)])
LoConfirm=”Using channel at Building 1”
echo “test conditon1”
echo $LoConfirm;;
[SM.APPLE_SWIFT_@(CV|CU|CS|BL)])
LoConfirm=”Using channel at Building 2”
echo “test condition2”
echo $LoConfirm;;
*) LoConfirm=”Unknown test”
echo $chl
echo $LoConfirm;;
esac

The variable alphachl can only contain one string which is either SM.APPLE_SWIFT_AL or SM.APPLE_SWIFT_DS or SM.APPLE_SWIFT_DU or SM.APPLE_SWIFT_DV. If it is one of these strings then prints a message "Using channel at Building 1". When I run the script, it just prints the messgae "Unknown test". I even tried to just insert the line [SM.APPLE_SWIFT_DV]) but still got the "Unknown test".

Is there anything wrong with my case syntax in particular the pattern matching bit please?

Thanks in advance...
Newbies.
# 2  
Old 03-18-2008
Variables are case sensitive, Chl isn't used proper in your script.

Regards
# 3  
Old 03-18-2008
The square brackets [] need to be quoted or escaped, as they are metacharacters for the case matching. It basically uses the same patterns as for file globbing (wildcards).

Also I don't think you can group substring alternatives inside parentheses.

Try this.

Code:
case $chl in
   '[SM.APPLE_SWIFT_@AL]' | '[SM.APPLE_SWIFT_@DS]' | '[SM.APPLE_SWIFT_@DU]' | '[SM.APPLE_SWIFT_@DV]DV)]') 
  ... etc

era
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern matching problem

if i have to do pattern match for file name with digit alphanumeric value like this File_1234.csv File_12sd45rg.csv i am using this File_*.csv and File_*.csv for digit pattern match. when i am doing pattern match for the digit then both alphanumeric match and digit match is coming. ... (3 Replies)
Discussion started by: ramsavi
3 Replies

2. Shell Programming and Scripting

Pattern matching problem

Hi I need a bash script that can search through a text file for all lines starting with 71502FSC1206 on every line it finds starting with this I need to place a letter F at the 127 position on that line. Thanks Paul (6 Replies)
Discussion started by: firefox2k2
6 Replies

3. Shell Programming and Scripting

Pattern matching and format problem

Hi I need a bash script that can search through a text file and when it finds 'FSS1206' I need to put a Letter F 100 spaces after the second instance of FSS1206 The format is the same throughout the file I need to repeat this on every time it finds the second 'FSS1206' in the file I have... (3 Replies)
Discussion started by: firefox2k2
3 Replies

4. Programming

pl sql . pattern matching problem

hi everyone i am facing a strange problem declare v_var number(10); begin if( regexp_like('RCDORMS_MMS_*_DAR','RCDORMS_MMS_*_DAR')) then v_var:=20; dbms_output.put_line(v_var); end if; end; / please tell me what's the wrong thing in this expression.. as i am not able to get... (1 Reply)
Discussion started by: aishsimplesweet
1 Replies

5. 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

6. Shell Programming and Scripting

pattern matching problem

# cat email.txt | grep -i "To:" To: <test@example.com> # cat email.txt | grep -i "Subject" Subject: Test Subject: How are you. I need to print only test@example.com from To field need to eliminate "< & >" from To field and need to print entire subject after Subject: It should be #... (7 Replies)
Discussion started by: mirfan
7 Replies

7. 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

8. Shell Programming and Scripting

Pattern Matching problem in UNIX

Hello All, I need help I have a problem in searching the pattern in a file let us say the file contains the below lines line 1 USING *'/FILE/FOLDER/RETURN') ................. ................. line 4 USING *'/FILE/FOLDER/6kdat1') line 5 USING... (2 Replies)
Discussion started by: maxmave
2 Replies

9. Shell Programming and Scripting

pattern matching problem

FilesToBackup='*.track* *.xml *.vm* *.gz Trace* TRACE* "*core*" *.out fcif_data_* esi_error_* *.rollback *.sed R.* APStatus_* log* *.output* send_mail* downenv* check_env* intaspurge_db_* sqlnet.log *.rpt *.html *.csv "*TSC*"' and i am using it like this- echo Moving files from $(pwd): ... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. Shell Programming and Scripting

pattern matching problem

I have a file with the following contents; NEW 85174 MP081 /29OCT07 CNL 85986 MP098 /28OCT07 NEW 86014 MP098 /28OCT07 NEW 86051 MP097 /27OCT07 CNL 86084 MP097 /27OCT07 Now I have to retrieve all lines that start with NEW and where the next line starts with CNL and where the MP codes are... (8 Replies)
Discussion started by: rein
8 Replies
Login or Register to Ask a Question