Requesting help to replace a string by my bash script

Hello every1,

I need help to replace a string in a file by my bash script.

Find: log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n= %d %5p [%t] (%F:%L) - %m%n

Replace: log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n

I tried by sed, but kept failing when it comes to find/replace special characters, will greatly appreciate if help me to resolve this issue.

Thanks................Sandeep

$ awk '/log4j/{print $0"%n"}' RS="%n=" file
log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n
$ sed '/log4j/s/\(.*%n=\).*/\1/g;s/=$//g' file
log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n
sed 's/\(log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n\)= %d %5p [%t] (%F:%L) - %m%n/\1/' file

sed solution without using the \( \) \1

sed '/^log4j/s/=[^=]*$//' infile
awk -F = '/log4j.appender.toLogFile.layout.ConversionPattern/ {NF=2}1' OFS="=" infile

Thank you very much everyone for these solution........:slight_smile:

Thanks.........Sandeep

# sed 's/%m%n=.*/%m%n/' infile

------