troubleshooting Question

SED Command to Insert Logging Line in Java File

Avatar of lcor
lcor asked on
Shell ScriptingRegular Expressions* AWK* sed
12 Comments2 Solutions234 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
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);' file.java
but this doesn't work.  It prints the logging statement mutliple times after below the public method call.

Any ideas what could be wrong?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 12 Comments.
Join the Community
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 2 Answers 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