Assume that we have an /etc/fstab
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:
/dev/alpha/photos /mnt/photos/ btrfs noauto,noatime,nodiratime 0 0
We want to change all lines from alpha
to beta
(the new VG name).
This can be done by the power of regular expressions
1
and this pipeline:
relpipe-in-fstab \
| relpipe-tr-sed \
--relation 'fstab' \
--attribute 'device' \
--value '^/dev/alpha/' \
--replacement '/dev/beta/' \
| relpipe-out-fstab
The relpipe-tr-sed
tool works only with given relation (fstab
) and given attribute (device
)
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).
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 dump
and pass
attributes:
relpipe-in-fstab \
| relpipe-tr-sed \
--relation 'fstab' \
--attribute 'dump|pass' \
--value '.+' \
--replacement '0' \
| relpipe-out-fstab
n.b. the data types must be respected, we can not e.g. put abc
in the pass
attribute because it is declared as integer
.
1.see Regular Expressions at Wikibooks
Relational pipes, open standard and free software © 2018-2022 GlobalCode