If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > shell script for pattern matching

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-06-09, 15:54
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
shell script for pattern matching

I am looking for a case statement pattern matching on a unix comment line.

For eg. given input in a file,
#aa=1
b=2
c=3
#ddd=4

so, the comment lines needs to be skipped while reading.

case "$line" in
aa) do_something;;
b) do_something;;
c) do_something;;
ddd) do_something;;
#) ;; /*NOT WORKING!! */
*) invalid input;;
esac

I tried couple of patterns but not working.

Thanks.
Reply With Quote
  #2 (permalink)  
Old 10-06-09, 16:16
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
It might help if you give an idea what the "do something" is.
Do the # lines get ignored?
Does the "aa" have to be at the start?
Does it matter what order you do the "somethings" in?
Reply With Quote
  #3 (permalink)  
Old 10-06-09, 17:04
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
Quote:
Originally Posted by mike_bike_kite
It might help if you give an idea what the "do something" is.
Do the # lines get ignored?
Does the "aa" have to be at the start?
Does it matter what order you do the "somethings" in?
All I want is comment lines (starts with #) need to be ignored. There is no certain order. Thanks.
Reply With Quote
  #4 (permalink)  
Old 10-06-09, 17:09
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,413
Cool grep'em

maybe something like this:
Code:
while read line
do
  case "$line" in
    aa*) do_something;;
     b*) do_something;;
     c*) do_something;;
   ddd*) do_something;;
    \#*) echo "this is a remark";;
      *) echo "invalid input";;
  esac
done
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 10-06-09, 17:22
deebee deebee is offline
Registered User
 
Join Date: Jul 2004
Posts: 45
Quote:
Originally Posted by LKBrwn_DBA
maybe something like this:
Code:
while read line
do
  case "$line" in
    aa*) do_something;;
     b*) do_something;;
     c*) do_something;;
   ddd*) do_something;;
    \#*) echo "this is a remark";;
      *) echo "invalid input";;
  esac
done
\#*) echo "this is a remark";;
WORKED! Thank you very much.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On