How to replace the following pattern in a java project
catch(SQLException e) {
\\TO DO
}
with
catch(SQLException e) { S.O.P(); }
Please note that the file will have other patterns like
catch(IOException e) {
// To Do }
which should not be changed.
I tried
sed 's/catch\(SQLException[^\}]*}/catch(SQLException e)\{S.O.P();\}/g' file.java
but it does not work.
you can use awk
Explanation: sEt the record separator to
}
. Then check forSQLException
. If found, set the record$0
to the new one. No complicated regex required.You can use this Perl script:
Sample run:
Input file:
Result: