tags:

views:

40

answers:

1

i have a huge .java file and i want to find all declared objects given the className. i think the declaration will always have the following signature:

className objName;

or

className objName =

or

className objName=

can someone suggest me a grep pattern which will find these signatures. I have the following (incomplete) :

    cat $rootFile | grep "$className " 

EXAMPLE :

If the input file is :

Policy pol1;
Policy pol2 ;
Policy   pol3  ;
Policy pol4=new Policy();
Policy pol5 = new Policy();
Policy pol6= new Policy();

I want to extract the following list :

pol1
pol2
pol3
pol4
pol5
pol6
+2  A: 

Probably perl can help here

cat $rootFilename | perl -pe 's/Policy[ \t]+([a-zA-Z0-9_]+)[ \t]*[;=].*/\1/g'

Using sed, can be done as well

sed -e 's/Policy[ \t]\+\([a-zA-Z0-9_]\+\)[ \t]*[;=].*/\1/g' $rootFilename
Kunal
Thanks Dennis!!
Kunal
Useless use of `cat`. Otherwise +1.
Dennis Williamson
Great thanks. This one work. Thanks to everyone for the contribution.
Amarsh