<stránka
xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
<nadpis>Using relpipe-tr-sed with groups and backreferences</nadpis>
<perex>sed-like substitution with regex groups and backreferences</perex>
<m:pořadí-příkladu>00800</m:pořadí-příkladu>
<text xmlns="http://www.w3.org/1999/xhtml">
<p>
This tool also support regex groups and backreferences. Thus we can use parts of the matched string in our replacement string:
</p>
<m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate r 1 a string "some string xxx_123 some zzz_456 other" \
| relpipe-tr-sed 'r' 'a' '([a-z]{3})_([0-9]+)' '$2:$1' \
| relpipe-out-tabular]]></m:pre>
<p>Which would convert this:</p>
<pre><![CDATA[r:
╭────────────────────────────────────────╮
│ a (string) │
├────────────────────────────────────────┤
│ some string xxx_123 some zzz_456 other │
╰────────────────────────────────────────╯
Record count: 1]]></pre>
<p>into this:</p>
<pre><![CDATA[r:
╭────────────────────────────────────────╮
│ a (string) │
├────────────────────────────────────────┤
│ some string 123:xxx some 456:zzz other │
╰────────────────────────────────────────╯
Record count: 1]]></pre>
<p>
If there were any other relations or attributes in the stream, they would be unaffected by this transformation,
becase we specified <code>'r' 'a'</code> instead of some wider regular expression that would match more relations or attributes.
</p>
</text>
</stránka>