原始文件内容
-bash-3.2# cat configTest.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<base-config>
<config-version>1</config-version>
<core>8</core>
<version>2.0</version>
</plugins>
</config>
示例1:
替换其中的,修改为2
sed -i "s/<core>[0-9]<\/core>.*$/<core>2<\/core>/g" configTest.xml
替换结果:
-bash-3.2# cat configTest.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<base-config>
<config-version>1</config-version>
<core>2</core>
<version>2.0</version>
</plugins>
</config>
示例2:
替换其中的
sed -i "s/<version>[0-9].[0-9]<\/version>/<version>3.5<\/version>/g" configTest.xml
替换结果:
-bash-3.2# cat configTest.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<base-config>
<config-version>1</config-version>
<core>6</core>
<version>3.5</version>
</plugins>
</config>
删除文件中的某一行
sed -i "/contextTobeDelete/d" fileName