pattern matching in case statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pattern matching in case statement
# 1  
Old 04-20-2009
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 $LINE in
"v5c0") echo "v5c0 found" ;;
"qacc1") echo "qacc1 found" ;;
*) echo "not found" ;;
esac
done < $FileName

the output for this code is:
qacc1 ----> down
not found
v5c0
v5c0 found
v5c1
not found

this code says not found if the pattern is in a line. like qacc1 ----> down
I have tried a number of patterns matching configurations and could get none of them to work. I am new to shell scripting and I am still learing.
It would be great if someone could help me with this.
# 2  
Old 04-20-2009
Code:
...
case $LINE in
*v5c0*) echo "v5c0 found" ;;
*qacc1*) echo "qacc1 found" ;
....

# 3  
Old 04-20-2009
thanks it works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Case statement help

Hi I am new to shell scripting, I wanted to make a shell script that has a case statement asking the user to select their city 1)london 2)tokyo 3) etc., I then want the users input to be stored in a variable and echoed out in another script; so for example if the user selects tokyo, tokyo city code... (2 Replies)
Discussion started by: scriptnewbie
2 Replies

2. Shell Programming and Scripting

Pattern Matching in IF-ELSE statement

Hi all, I am trying to use an if statement to see whether a variable falls under any of the 5 patterns: if ] then echo "something" else echo "Please enter a correct division" fi The problem is despite having the variable DIV as "ter", "bom", "hre", "nte", or "mol" it will... (6 Replies)
Discussion started by: MIA651
6 Replies

3. Homework & Coursework Questions

Case Statement

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hey, guys I really need some help with a project. "Write a shell program that examines the command line... (8 Replies)
Discussion started by: sk192010`
8 Replies

4. Shell Programming and Scripting

Case Statement

Hey, guys I really need some help with a project. "Write a shell program that examines the command line arguments, counts and collects the number of options. Basically it has to collect and count the arguments that start with a "-" and the one's that don't start with a - I know I have to use... (2 Replies)
Discussion started by: sk192010`
2 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

case statement

Hi, I am writing case statement to execute some finction, my requirement is once one of the case statement is executed again it has to prompt for the option. for script in `echo "$Script_Selected"` do case $script in 1) getNoOFActUsers ;; 2) moveServerrOORotation ;; ... (2 Replies)
Discussion started by: Satyak
2 Replies

7. Shell Programming and Scripting

case statement

Hi all, I think i'm asking a sqtupid question here.. i'm using case sttament, what is the syntax or symbol for "or"? I thought was || here a quick sample of my case statment echo "Would you like to update your detail ?" read response case $response in ... (2 Replies)
Discussion started by: c00kie88
2 Replies

8. UNIX for Dummies Questions & Answers

If or Case Statement

I want to write a program with the following variables: a=7000 b=24000 c=613.8 The user can enter two words: Vivid or Blue for example. The challenge is that the user might not want to write the words the way they appear. The user can write V or v or vivid or Vivid or write Blue or blue, or B,... (1 Reply)
Discussion started by: Ernst
1 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

case statement

Hi all, is it possible to create a 'dynamic' case statement. ie select option in `ls` do case satement depending on results of the above `ls` done I hope I have explained this ok! Thanks Helen (1 Reply)
Discussion started by: Bab00shka
1 Replies
Login or Register to Ask a Question