开发者

bash grep finding java declarations

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
p开发者_高级运维ol4
pol5
pol6


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜