我不知道这是怎么回事,以为我已经安排好了,但没有
我有一个XML文件,其条目如下所示
<compat-change description="Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used to pass while-in-use capabilities from client process to bound service. In targetSdkVersion R and above, if client is a TOP activity, when this flag is present, bound service gets all while-in-use capabilities; when this flag is not present, bound service gets no while-in-use capability from client." enableAfterTargetSdk="29" id="136274596" name="PROCESS_CAPABILITY_CHANGE_ID"/>我需要匹配id和name (总是静态值,并按相同的顺序排列),但是更改Sdk值(它是可变的)。
Sdk="29" id="136274596" name="PROCESS_CAPABILITY"我确实试过
sed -i '/Sdk=\"[0-9]\+\".*id="143937733".*name="PROCESS_CAPABILITY"/ {s/Sdk=\"[0-9]\+\"/Sdk=\"0\"/1;}'任何建议都非常感谢
发布于 2022-09-01 20:39:14
使用适当的XML工具(如xmlstarlet )会更好,比如
xmlstarlet ed -u '
//compat-change[@id="136274596"][starts-with(@name,"PROCESS_CAPABILITY")]/@enableAfterTargetSdk
' -v 0 file.xml例如。
$ xmlstarlet ed -u '//compat-change[@id="136274596"][starts-with(@name,"PROCESS_CAPABILITY")]/@enableAfterTargetSdk' -v 0 file.xml
<?xml version="1.0"?>
<compat-change description="Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used to pass while-in-use capabilities from client process to bound service. In targetSdkVersion R and above, if client is a TOP activity, when this flag is present, bound service gets all while-in-use capabilities; when this flag is not present, bound service gets no while-in-use capability from client." enableAfterTargetSdk="0" id="136274596" name="PROCESS_CAPABILITY_CHANGE_ID"/>发布于 2022-09-01 21:47:17
使用sed
$ sed -E 's/(Sdk=")[^"]*(" id="136274596" name="PROCESS_CAPABILITY)/\10\2/' input_file
<compat-change description="Flag {@link android.content.Context#BIND_INCLUDE_CAPABILITIES} is used to pass while-in-use capabilities from client process to bound service. In targetSdkVersion R and above, if client is a TOP activity, when this flag is present, bound service gets all while-in-use capabilities; when this flag is not present, bound service gets no while-in-use capability from client." enableAfterTargetSdk="0" id="136274596" name="PROCESS_CAPABILITY_CHANGE_ID"/>https://unix.stackexchange.com/questions/715804
复制相似问题