У меня есть файл xml, в который мне нужно вставить несколько строк в случайных местах. Я пытаюсь использовать sed / awk, но сталкиваюсь с некоторыми проблемами.
Вот что я пытаюсь сделать.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manager name="Manager1" exportDate="2020-01-13-05:00" comment=" configuration from 0.0.0.0">
<ChannelSet>
<ChannelEntry>
<ChannelAttributesEntry name="/Pub/Sub/commands" TTL="0" capacity="0" EID="15" clusterWide="true" jmsEngine="true" mergeEngine="false" type="RELIABLE_TYPE"/>
<StorePropertiesEntry CacheOnReload="false" Priority="1"/>
<ChannelPermissionSet>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Admin Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="false" publish="true" useNamedSubcription="false" groupname="Web Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="true" publish="false" useNamedSubcription="false" groupname="Messenger Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Retry Service Group"/>
</ChannelPermissionSet>
</ChannelEntry>
<ChannelEntry>
<StorePropertiesEntry CacheOnReload="false" Priority="1"/>
<ChannelPermissionSet>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Admin Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="true" publish="false" useNamedSubcription="true" groupname="Highland Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="false" publish="true" useNamedSubcription="false" groupname="Aus Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="false" publish="true" useNamedSubcription="false" groupname="Q Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Retry Service Group"/>
</ChannelPermissionSet>
</ChannelEntry>
<QueueSet>
<QueueEntry>
<ChannelAttributesEntry name="/3m/receive/events" TTL="0" capacity="0" EID="0" clusterWide="true" jmsEngine="false" mergeEngine="false" type="PERSISTENT_TYPE"/>
<StorePropertiesEntry HonorCapacityWhenFull="false" CacheOnReload="false"/>
<QueuePermissionSet>
<QueueACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" host="*" name="lijhlkjnlkjhlk"/>
<QueueACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="true" push="true" pop="false" host="*" name="eeff456987987"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="false" pop="true" groupname="3m Group"/>
</QueuePermissionSet>
</QueueEntry>
<QueueEntry>
<ChannelAttributesEntry name="/7m/receive/fault/events" TTL="0" capacity="0" EID="0" clusterWide="true" jmsEngine="false" mergeEngine="false" type="PERSISTENT_TYPE"/>
<StorePropertiesEntry CacheOnReload="false"/>
</QueueEntry>
<QueueEntry>
<ChannelAttributesEntry name="/Orchestration/bigData/fault/gen" TTL="0" capacity="0" EID="0" clusterWide="true" jmsEngine="false" mergeEngine="false" type="PERSISTENT_TYPE"/>
<StorePropertiesEntry CacheOnReload="false"/>
<QueuePermissionSet>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" groupname="Big Data Group"/>
</QueuePermissionSet>
</QueueEntry>
Я пытаюсь вставить строки
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" purge="false" peek="false" push="false" pop="false" groupname="Admin Group"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" groupname="SBGroup"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="true" push="false" pop="false" groupname="SMS Admin"/>
в каждую запись очереди.
Таким образом, мой окончательный вариант c должен выглядеть следующим образом:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manager name="Manager1" exportDate="2020-01-13-05:00" comment=" configuration from 0.0.0.0">
<ChannelSet>
<ChannelEntry>
<ChannelAttributesEntry name="/Pub/Sub/commands" TTL="0" capacity="0" EID="15" clusterWide="true" jmsEngine="true" mergeEngine="false" type="RELIABLE_TYPE"/>
<StorePropertiesEntry CacheOnReload="false" Priority="1"/>
<ChannelPermissionSet>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Admin Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="false" publish="true" useNamedSubcription="false" groupname="Web Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="true" publish="false" useNamedSubcription="false" groupname="Messenger Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Retry Service Group"/>
</ChannelPermissionSet>
</ChannelEntry>
<ChannelEntry>
<StorePropertiesEntry CacheOnReload="false" Priority="1"/>
<ChannelPermissionSet>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Admin Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="true" publish="false" useNamedSubcription="true" groupname="Highland Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="false" publish="true" useNamedSubcription="false" groupname="Aus Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" getLastEID="true" purgeEvents="false" subscribe="false" publish="true" useNamedSubcription="false" groupname="Q Group"/>
<ChannelGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" getLastEID="false" purgeEvents="false" subscribe="false" publish="false" useNamedSubcription="false" groupname="Retry Service Group"/>
</ChannelPermissionSet>
</ChannelEntry>
<QueueSet>
<QueueEntry>
<ChannelAttributesEntry name="/3m/receive/events" TTL="0" capacity="0" EID="0" clusterWide="true" jmsEngine="false" mergeEngine="false" type="PERSISTENT_TYPE"/>
<StorePropertiesEntry HonorCapacityWhenFull="false" CacheOnReload="false"/>
<QueuePermissionSet>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" purge="false" peek="false" push="false" pop="false" groupname="Admin Group"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" groupname="SBGroup"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="true" push="false" pop="false" groupname="SMS Admin"/>
<QueueACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" host="*" name="lijhlkjnlkjhlk"/>
<QueueACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="true" push="true" pop="false" host="*" name="eeff456987987"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="false" pop="true" groupname="3m Group"/>
</QueuePermissionSet>
</QueueEntry>
<QueueEntry>
<ChannelAttributesEntry name="/7m/receive/fault/events" TTL="0" capacity="0" EID="0" clusterWide="true" jmsEngine="false" mergeEngine="false" type="PERSISTENT_TYPE"/>
<StorePropertiesEntry CacheOnReload="false"/>
<QueuePermissionSet>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" purge="false" peek="false" push="false" pop="false" groupname="Admin Group"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" groupname="SBGroup"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="true" push="false" pop="false" groupname="SMS Admin"/>
</QueuePermissionSet>
</QueueEntry>
<QueueEntry>
<ChannelAttributesEntry name="/Orchestration/bigData/fault/gen" TTL="0" capacity="0" EID="0" clusterWide="true" jmsEngine="false" mergeEngine="false" type="PERSISTENT_TYPE"/>
<StorePropertiesEntry CacheOnReload="false"/>
<QueuePermissionSet>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="true" purge="false" peek="false" push="false" pop="false" groupname="Admin Group"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" groupname="SBGroup"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="true" push="false" pop="false" groupname="SMS Admin"/>
<QueueGroupACLEntry listACLEntries="false" modifyACLEntries="false" fullControl="false" purge="false" peek="false" push="true" pop="false" groupname="Big Data Group"/>
</QueuePermissionSet>
</QueueEntry>
Я пытался использовать sed -i '/<QueuePermissionSet>/a\ followed by three lines' filename
, но в нем отсутствует тот, у которого нет <QueuePermissionSet>
.
Я пытался использовать awk, но это тоже не работает. Еще одна идея, которую я тестирую, заключается в проверке строки l oop и вставке строки, если найдено совпадение. У меня возникли проблемы с вставкой строк в этой конкретной точке файла.
Пожалуйста, помогите.