AWK script for programatically modifying java files

Hi,
I want to add a String variable to all java classes in my project. Assuming a class like

public class Random
{
String var="Constant string";
...
...
...
}

The text in bold is what I want to add to all java files in my workspace.
I am an absolute newbie to AWK, and read somewhere that its easily doable in AWK, and am currently hurrying through the online tutorials.. could anyone please help me with a script if its not really complex?

Thanks in advance!

 
 
awk '/public class/ { print;getline;print;getline;print "String var=\"Constant string\";"; }1' input_file > out_file;
 
mv out_file in_file

loop thorugh

"for file_name in `ls *.java`"

to do the change on all files.

nawk -v ins='String var="Constant string";' '/public class/{c=2;next} c-- && !c{print ins}1' myClassFile

This is a combo useless use of ls * and useless use of backticks. Why do 'for file in `ls *.java` when you can do for file in *.java ?

awk '{if($0~/\{/ && !b){a=1;b=1;print $0;next;} if(a){print "String abc=\"xxxxx\";";a=0}print $0}'  yourFile.java

then you can

 find . -name *.java|xargs ... 

to do it on all your java files.

Thanks for the quick reply guys,

I tried running this, and it gave me this error:

awk: Syntax error  Context is:
>>>     {if($0~/\{/     <<<

The following worked perfectly however for me,

awk '/public class/ { print;getline;print;getline;print "String var=\"Constant string\";"; }1' input_file > out_file;
 
mv out_file in_file

thanks!