Добавление строк в середине файла с помощью сценария оболочки - PullRequest
1 голос
/ 14 января 2020

У меня есть файл 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 и вставке строки, если найдено совпадение. У меня возникли проблемы с вставкой строк в этой конкретной точке файла.

Пожалуйста, помогите.

Ответы [ 2 ]

2 голосов
/ 15 января 2020

Я бы не рекомендовал делать это с помощью sed / regex. (См. связанный ответ здесь.) Возможно, поэтому ваш вопрос был отредактирован для добавления тега xmlstarlet.

Если вы можете использовать xmlstarlet, я бы использовал команду xmlstarlet tr для преобразования с XSLT.

В дополнение к преобразование идентичности , вам понадобятся два других шаблона. Один соответствует существующему QueuePermissionSet, а другой - QueueEntry, у которого еще нет QueuePermissionSet.

Пример ...

xmlstarlet * Командная строка

xmlstarlet tr so.xsl input.xml > output.xml

XML Вход (вход. xml)

<?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>
        </QueueSet>
    </ChannelSet>
</Manager>

XSLT 1.0 (so.xsl)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" encoding="UTF-8" standalone="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:variable name="entries">
    <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"/>
  </xsl:variable>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="QueuePermissionSet">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:copy-of select="$entries"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="QueueEntry[not(QueuePermissionSet)]">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <QueuePermissionSet>
        <xsl:copy-of select="$entries"/>        
      </QueuePermissionSet>
    </xsl:copy>  
  </xsl:template>

</xsl:stylesheet>

XML Выход (выход. xml)

<?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>
    </QueueSet>
  </ChannelSet>
</Manager>
1 голос
/ 14 января 2020

Вам действительно нужно только find файл (ы) и команда exec a sed.

Запустить эту команду из каталога, в котором находится файл:

find ./yourfile.xml -type f -readable -writable -exec sed -i "s/<QueuePermissionSet>/<QueuePermissionSet>\n\t\t<QueueGroupACLEntry listACLEntries=\"false\" modifyACLEntries=\"false\" fullControl=\"true\" purge=\"false\" peek=\"false\" push=\"false\" pop=\"false\" groupname=\"Admin Group\"\/>\n\t\t<QueueGroupACLEntry listACLEntries=\"false\" modifyACLEntries=\"false\" fullControl=\"false\" purge=\"false\" peek=\"false\" push=\"true\" pop=\"false\" groupname=\"SBGroup\"\/>\n\t\t<QueueGroupACLEntry listACLEntries=\"false\" modifyACLEntries=\"false\" fullControl=\"false\" purge=\"false\" peek=\"true\" push=\"false\" pop=\"false\" groupname=\"SMS Admin\"\/>\n/g" {} \;

Я знаю, что это выглядит грязно в одной строке .. Но .. Вам нужно избежать кавычек \", а также избежать слова sh при закрытии тегов \/> Я также взял на себя свободу добавление новых строк \n и вкладок \t для упрощения форматирования.

ИСПЫТАНО:

До:

<?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>

После:

<?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"/>
        </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>
...