I have an xml that looks like following.
<rootNode>
<appender name="SERVER_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/COM_FIND.log"/>
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<appender name="CAT_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/COM_Now.log"/>
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<appender name="SERVER_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/COM_A.log"/>
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<appender name="SERVER_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/COM_Find.log"/>
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<logger name="com.mycompany">
<level value="INFO"/>
<appender-ref ref="SERVER_FILE"/>
</logger>
</rootNode>
Yes.Its an excerpt from the log4j xml. What i basically want to do is remove all the appender tags/elements (from )that contain the word 'COM_Find.log' using the sed command.
What i have so far is this :-
sed -e '/<appender/,/</appender>/{H;$!d;}' -e 'x;/COM_Find.log/d' file.xml
Which does a greedy search from the first appender to the last and deletes everything in between. I just want only those specific appender tags/elements(from ) to be removed.
The output should be:-
<rootNode>
<appender name="CAT_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/COM_Now.log"/>
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<appender name="SERVER_FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:/COM_A.log"/>
<param name="Threshold" value="INFO"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="5000KB"/>
<param name="MaxBackupIndex" value="5"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<logger name="com.mycompany">
<level value="INFO"/>
<appender-ref ref="SERVER_FILE"/>
</logger>
</rootNode>
Can someone help me?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…