sedを使用して複数行に文字列を挿入しようとしていますが、目的の結果は得られません。
私はこれを持っています:
<p begin="540960420t" end="600189590t" xml:id="subtitle8">-Some text.<br/>-Some more text</p>
<p begin="601020420t" end="653572920t" xml:id="subtitle9">-Something else<br/>Some more text</p>
<p begin="654403750t" end="731560830t" xml:id="subtitle10">More words<br/>-more text</p>
<p begin="732401670t" end="786625840t" xml:id="subtitle11">Some text.<br/>Some more text</p>
これを挿入する必要があります
<span style="style0">
「字幕[0-200]」>の前には次のようになります。
<p begin="540960420t" end="600189590t" xml:id="subtitle8"><span style="style0">-Some text.<br/>-Some more text</p>
<p begin="601020420t" end="653572920t" xml:id="subtitle9"><span style="style0">-Some text.<br/>Some more text</p>
など...
私は次のことを試しています:
cat demo.xml | sed 's/xml:id="subtitle[0-9]">/<span style="style0"><p/g'
しかし、これは変えるxml:id="subtitle[0-9]"> および subtitle0 から subtile9 までのみ
私はすべてのsedと正規表現関連の内容に初めて触れました。他のものがsedよりも簡単であれば問題になりません。
安否挨拶サウロン
ベストアンサー1
あなたはできます:
sed 's/subtitle[0-9]\{1,3\}">/&<span style="style0">/'
1〜3桁の数字の一致を使用して、字幕[0-200]と一致し、追加された\{1,3\}
一致パターンに置き換えられます<span style...
。
次のように入力する場合:
<p begin="540960420t" end="600189590t" xml:id="subtitle8">-Some text.<br/>-Some more text</p>
<p begin="601020420t" end="653572920t" xml:id="subtitle9">-Something else<br/>Some more text</p>
<p begin="654403750t" end="731560830t" xml:id="subtitle10">More words<br/>-more text</p>
<p begin="732401670t" end="786625840t" xml:id="subtitle11">Some text.<br/>Some more text</p>
これは出力されます
<p begin="540960420t" end="600189590t" xml:id="subtitle8"><span style="style0">-Some text.<br/>-Some more text</p>
<p begin="601020420t" end="653572920t" xml:id="subtitle9"><span style="style0">-Something else<br/>Some more text</p>
<p begin="654403750t" end="731560830t" xml:id="subtitle10"><span style="style0">More words<br/>-more text</p>
<p begin="732401670t" end="786625840t" xml:id="subtitle11"><span style="style0">Some text.<br/>Some more text</p>