Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于更新特定记录中的xml字段的bash脚本_Xml_Bash_Shell - Fatal编程技术网

用于更新特定记录中的xml字段的bash脚本

用于更新特定记录中的xml字段的bash脚本,xml,bash,shell,Xml,Bash,Shell,我是一个新手 我需要一个xml记录: <record name="lteRanRf"> <key name="fapService" value="1"/> <field name="referenceSignalPower" value="-10"/> <field name="phyCellId" value="2175"/> </record> <record name="neighborcel

我是一个新手

我需要一个xml记录:

 <record name="lteRanRf">
    <key name="fapService" value="1"/>
    <field name="referenceSignalPower" value="-10"/>
    <field name="phyCellId" value="2175"/>
 </record>
 <record name="neighborcell">
    <key name="fapService" value="1"/>
    <field name="referenceSignalPower" value="-10"/>
    <field name="phyCellId" value="2175"/>
 </record>
我只需要替换lteRanRf记录中phyCellId的值。 任何帮助都将不胜感激


提前感谢。

下面的awk命令将更改记录lteRanRf中phyCellId字段的值


要更改的值在awk命令中给出,即,$14=1111

你想用什么替换它?我需要将phyCellId的值从2175更新为用户输入值,仅在record lteRanRf中,并且我只能使用bash脚本。你能解释一下这个命令是如何工作的吗?如果我运行这个命令,整个xml都会被打印出来。它不会改变phyCellId:那么它可能包含space,我完全复制了你发布的内容,并以此为基础进行了工作。用正则表达式解析XML太难了。
$ awk -F'"' -v RS="</record>" 'BEGIN{OFS=FS; ORS=RS;} /lteRanRf/ {$14=1111;}1' file
 <record name="lteRanRf">
    <key name="fapService" value="1"/>
    <field name="referenceSignalPower" value="-10"/>
    <field name="phyCellId" value="1111"/>
 </record>
 <record name="neighborcell">
    <key name="fapService" value="1"/>
    <field name="referenceSignalPower" value="-10"/>
    <field name="phyCellId" value="2175"/>
 </record>