Question : Pattern matching in shell script

I need to write a script which can do the followings ---
1> check if the line has ---> class (followed by tab or spaces) class name shouldn't start with lower case letters or numerics, it should only start with Upper case followed by lower case alphabets.
like, class MyClass
not class myClass

2> all the variables should start with lower case first letter, like
 String myString
or int myInt
or long myLong
or double myDouble
or boolean myBoolean

I want to do it with sed, I'm trying to do this, but its not working, pls help.
s/class .*'[^a-z0-9]'.*/\/\/ERR: class name should start with Upper case*** /g

Regards
prasen

Answer : Pattern matching in shell script

using sed which makes use of lots of regexp can make your code uneasy to read. try something more readable (aka less regexp), that makes use of fields eg awk. You know the word following class, int , float are the second field. therefore you can do this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
awk '
/^class/ && $2 !~ /^[A-Z]/{
  print $0 ,"//ERR: class name should start with Upper case***"
  next
}
/^ +(int|double|boolean|float|String)/ && $2 !~ /^[A-Z]/{  
  print $0,"//ERR: varible name should start with Upper case***"
  next
} 1
' file
Open in New Window Select All
Random Solutions  
 
programming4us programming4us