XMLファイルの編集 - 文字列を見つけてテキストブロックを削除し、/文字列を見つけて新しいテキストブロックを挿入します。

XMLファイルの編集 - 文字列を見つけてテキストブロックを削除し、/文字列を見つけて新しいテキストブロックを挿入します。

みんなこんにちは、

私はUNIXに初めて触れたので、VBでできることをしたかったのですが、UNIXでは試した経験はありません。

新しいReuters RICコードがオンラインになったときに定期的に削除して更新する必要がある共有XML仕様があります。実装する2つのプロジェクト:

A. RICエントリの削除

  1. ファイルを開く
  2. 特定の文字列を探す
  3. 見つかった行とその下の21行を削除します。
  4. アーカイブの保存

私の考えでは、これがうまくいくようです:

sed –e '/<ric id="AUG03250639E=YBAU">/,+21d'  a.xml >a.xml

B. 新しいRIC項目を追加

  1. ファイルを開く
  2. 最後に発生したスティングを探す</source>
  3. 最後のRIC入力ブロックまで29行上に移動
  4. この行と下の21行をコピーしてください(ricブロック)。
  5. 22行目の下に新しい行を挿入し、このブロック(新しいブロック)をコピーしたブロックのすぐ下に貼り付けます。
  6. 新しいブロックの行1のricを新しいRic文字列に変更します<ricid="AAAAA=YBAU"<ricid="BBBBB=YBAU"
  7. アーカイブの保存

どうすればいいですか?

ファイルの最後の部分です。 (私が操作したい)ricブロックの終わりは、次の文字列が表示されるときです。 。 。

            <ric id="AUG03250639E=YBAU">
                <securities>
                    <security>
                        <issueid>178117</issueid>
                        <quote-type>YIELD</quote-type>
                        <complex-logic>
                            <calculations>
                                <yield-type>
                                    <type>BID_YIELD</type>
                                    <calculation name="AB" field="RT_YIELD_1" />
                                </yield-type>
                                <yield-type>
                                    <type>OFFER_YIELD</type>
                                    <calculation name="AB" field="SEC_YLD_1" />
                                </yield-type>
                            </calculations>
                        </complex-logic>
                        <derived-type name="PRICE" baseValue="100.0" />
                    </security>
                </securities>
            </ric>
            <ric id="AUG03250640E=YBAU">
                <securities>
                    <security>
                        <issueid>178117</issueid>
                        <quote-type>YIELD</quote-type>
                        <complex-logic>
                            <calculations>
                                <yield-type>
                                    <type>BID_YIELD</type>
                                    <calculation name="AB" field="RT_YIELD_1" />
                                </yield-type>
                                <yield-type>
                                    <type>OFFER_YIELD</type>
                                    <calculation name="AB" field="SEC_YLD_1" />
                                </yield-type>
                            </calculations>
                        </complex-logic>
                        <derived-type name="PRICE" baseValue="100.0" />
                    </security>
                </securities>
            </ric>
        </rics>
        <topics>
            <topic>
                <id>default</id>
                <type>rmds</type>
                <value>IDN_SELECTFEED.ANY.%s.NaE</value>
            </topic>
        </topics>
    </source>

    <transformers>
        <!-- Name of transformer -->
        <transformer></transformer>
    </transformers>

    <processors>
        <!-- Enricher to add additional fields from source query result while 
            publishing -->
        <processor></processor>
    </processors>
    <endpoints>
        <!-- Order of post processor is important. First topic, then mapper -->

        <endpoint id="rmds" topic="FI.ANY.%s.YBAU" multicast="true">

            <postprocessor>reuters-topic-builder</postprocessor>
            <postprocessor>reuters-message-mapper</postprocessor>
            <!-- <multitopic id="solace" topic="LN/FI/IP/APS/SSHEET/YIELD/BATS_%s" 
                /> -->
            <multitopic id="solace-credit" topic="LN/FI/EP/CREDITBPS/SSHEET/BATS_%s" />
            <multitopic id="solace-credit" topic="LN/FI/EP/CREDITBPS/YIELDBROKER/BATS_%s" />
        </endpoint>

    </endpoints>
    <other-properties>
        <!-- common formatting of price/yield -->
        <property name="formattor-1">(math:pow(INPUT/100+1,0.5)-1)*200</property>
        <property name="handle_negative_values">false</property>
        <property name="handle_negative_values_output">0.001</property>
    </other-properties>
</specification>

したがって、A. AUG03250640E=YBAU を削除しようとしている RIC 項目を削除すると、ファイルに以下が表示されます。

            <ric id="AUG03250639E=YBAU">
                <securities>
                    <security>
                        <issueid>178117</issueid>
                        <quote-type>YIELD</quote-type>
                        <complex-logic>
                            <calculations>
                                <yield-type>
                                    <type>BID_YIELD</type>
                                    <calculation name="AB" field="RT_YIELD_1" />
                                </yield-type>
                                <yield-type>
                                    <type>OFFER_YIELD</type>
                                    <calculation name="AB" field="SEC_YLD_1" />
                                </yield-type>
                            </calculations>
                        </complex-logic>
                        <derived-type name="PRICE" baseValue="100.0" />
                    </security>
                </securities>
            </ric>
        </rics>
        <topics>
            <topic>
                <id>default</id>
                <type>rmds</type>
                <value>IDN_SELECTFEED.ANY.%s.NaE</value>
            </topic>
        </topics>
    </source>

    <transformers>
        <!-- Name of transformer -->
        <transformer></transformer>
    </transformers>

    <processors>
        <!-- Enricher to add additional fields from source query result while 
            publishing -->
        <processor></processor>
    </processors>
    <endpoints>
        <!-- Order of post processor is important. First topic, then mapper -->

        <endpoint id="rmds" topic="FI.ANY.%s.YBAU" multicast="true">

            <postprocessor>reuters-topic-builder</postprocessor>
            <postprocessor>reuters-message-mapper</postprocessor>
            <!-- <multitopic id="solace" topic="LN/FI/IP/APS/SSHEET/YIELD/BATS_%s" 
                /> -->
            <multitopic id="solace-credit" topic="LN/FI/EP/CREDITBPS/SSHEET/BATS_%s" />
            <multitopic id="solace-credit" topic="LN/FI/EP/CREDITBPS/YIELDBROKER/BATS_%s" />
        </endpoint>

    </endpoints>
    <other-properties>
        <!-- common formatting of price/yield -->
        <property name="formattor-1">(math:pow(INPUT/100+1,0.5)-1)*200</property>
        <property name="handle_negative_values">false</property>
        <property name="handle_negative_values_output">0.001</property>
    </other-properties>
</specification>

B. 新しい RIC 項目を追加する場合は、新しい ric AUG03250641E=YBAU を追加すると仮定すると、ファイルに以下が表示されます。

            <ric id="AUG03250639E=YBAU">
                <securities>
                    <security>
                        <issueid>178117</issueid>
                        <quote-type>YIELD</quote-type>
                        <complex-logic>
                            <calculations>
                                <yield-type>
                                    <type>BID_YIELD</type>
                                    <calculation name="AB" field="RT_YIELD_1" />
                                </yield-type>
                                <yield-type>
                                    <type>OFFER_YIELD</type>
                                    <calculation name="AB" field="SEC_YLD_1" />
                                </yield-type>
                            </calculations>
                        </complex-logic>
                        <derived-type name="PRICE" baseValue="100.0" />
                    </security>
                </securities>
            </ric>
            <ric id="AUG03250640E=YBAU">
                <securities>
                    <security>
                        <issueid>178117</issueid>
                        <quote-type>YIELD</quote-type>
                        <complex-logic>
                            <calculations>
                                <yield-type>
                                    <type>BID_YIELD</type>
                                    <calculation name="AB" field="RT_YIELD_1" />
                                </yield-type>
                                <yield-type>
                                    <type>OFFER_YIELD</type>
                                    <calculation name="AB" field="SEC_YLD_1" />
                                </yield-type>
                            </calculations>
                        </complex-logic>
                        <derived-type name="PRICE" baseValue="100.0" />
                    </security>
                </securities>
            </ric>
            <ric id="AUG03250641E=YBAU">
                <securities>
                    <security>
                        <issueid>178117</issueid>
                        <quote-type>YIELD</quote-type>
                        <complex-logic>
                            <calculations>
                                <yield-type>
                                    <type>BID_YIELD</type>
                                    <calculation name="AB" field="RT_YIELD_1" />
                                </yield-type>
                                <yield-type>
                                    <type>OFFER_YIELD</type>
                                    <calculation name="AB" field="SEC_YLD_1" />
                                </yield-type>
                            </calculations>
                        </complex-logic>
                        <derived-type name="PRICE" baseValue="100.0" />
                    </security>
                </securities>
            </ric>
        </rics>
        <topics>
            <topic>
                <id>default</id>
                <type>rmds</type>
                <value>IDN_SELECTFEED.ANY.%s.NaE</value>
            </topic>
        </topics>
    </source>

    <transformers>
        <!-- Name of transformer -->
        <transformer></transformer>
    </transformers>

    <processors>
        <!-- Enricher to add additional fields from source query result while 
            publishing -->
        <processor></processor>
    </processors>
    <endpoints>
        <!-- Order of post processor is important. First topic, then mapper -->

        <endpoint id="rmds" topic="FI.ANY.%s.YBAU" multicast="true">

            <postprocessor>reuters-topic-builder</postprocessor>
            <postprocessor>reuters-message-mapper</postprocessor>
            <!-- <multitopic id="solace" topic="LN/FI/IP/APS/SSHEET/YIELD/BATS_%s" 
                /> -->
            <multitopic id="solace-credit" topic="LN/FI/EP/CREDITBPS/SSHEET/BATS_%s" />
            <multitopic id="solace-credit" topic="LN/FI/EP/CREDITBPS/YIELDBROKER/BATS_%s" />
        </endpoint>

    </endpoints>
    <other-properties>
        <!-- common formatting of price/yield -->
        <property name="formattor-1">(math:pow(INPUT/100+1,0.5)-1)*200</property>
        <property name="handle_negative_values">false</property>
        <property name="handle_negative_values_output">0.001</property>
    </other-properties>
</specification>

ベストアンサー1

~のためPOSIXsedheadユーティリティはもちろん一般in文書:

{   sed  -ne'/^<ric id="AUG03250639E=YBAU">$/q;p'
    head -n21 >/dev/null
    cat
}   <in >out

おすすめ記事