troubleshooting Question

SED Command to Insert Logging Line in Java File

Avatar of lcor
lcor asked on
Regular ExpressionsShell Scripting* sed* AWK
12 Comments1 Solution234 ViewsLast Modified:
I need to modify alot of java files so that each method prints a logging message so hopefully sed will do the trick for me.

Here's an example of the file change.
public void someMethod(int x) {
     System.out.println("xx"); // Sed command should add this line to the java file for every method in the file

Open in new window

I tried using the following sed command to look for public as the starting pattern and the ending pattern of right paren, space, left bracket.
sed '/public/,/) {/a System.out.println("xx);'

Open in new window

but this doesn't work.  It prints the logging statement mutliple times after below the public method call.

Any ideas what could be wrong?
Requirement analysis,Application Development,Automation Management.Senior Manager 16+. Knowledge transfer 19+.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros