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
cabrao
2
$ 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
ctsgnb
4
sed solution without using the \( \) \1
sed '/^log4j/s/=[^=]*$//' infile
rdcwayx
5
awk -F = '/log4j.appender.toLogFile.layout.ConversionPattern/ {NF=2}1' OFS="=" infile
Thank you very much everyone for these solution........
Thanks.........Sandeep
ygemici
7
# sed 's/%m%n=.*/%m%n/' infile