<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>Renaming VG in /etc/fstab using relpipe-tr-sed</nadpis>
<perex>sed-like substitutions in the relational stream</perex>
<m:pořadí-příkladu>00700</m:pořadí-příkladu>
<text xmlns="http://www.w3.org/1999/xhtml">
<p>
Assume that we have an <code>/etc/fstab</code> with many lines defining the mount-points (directories) of particular devices (disks) and we are using LVM.
If we rename a volume group (VG), we have to change all of them. The lines look like this one:
</p>
<pre>/dev/alpha/photos /mnt/photos/ btrfs noauto,noatime,nodiratime 0 0</pre>
<p>
We want to change all lines from <code>alpha</code> to <code>beta</code> (the new VG name).
This can be done by the power of regular expressions<m:podČarou>see <a href="https://en.wikibooks.org/wiki/Regular_Expressions/Simple_Regular_Expressions">Regular Expressions</a> at Wikibooks</m:podČarou> and this pipeline:
</p>
<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \
| relpipe-tr-sed \
--relation 'fstab' \
--attribute 'device' \
--value '^/dev/alpha/' \
--replacement '/dev/beta/' \
| relpipe-out-fstab]]></m:pre>
<p>
The <code>relpipe-tr-sed</code> tool works only with given relation (<code>fstab</code>) and given attribute (<code>device</code>)
and it would leave untouched other relations and attributes in the stream.
So it would not replace the strings on unwanted places (if there are any random matches).
</p>
<p>
Even the relation names and attribute names are specified as a regular expression, so we can (purposefully) modify multiple relations or attributes.
For example we can put zeroes in both <code>dump</code> and <code>pass</code> attributes:
</p>
<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \
| relpipe-tr-sed \
--relation 'fstab' \
--attribute 'dump|pass' \
--value '.+' \
--replacement '0' \
| relpipe-out-fstab]]></m:pre>
<p>
n.b. the data types must be respected, we can not e.g. put <code>abc</code> in the <code>pass</code> attribute because it is declared as <code>integer</code>.
</p>
</text>
</stránka>