# HG changeset patch # User František Kučera # Date 1544467428 -3600 # Node ID 4e45b9a177c295b89841c4ed9a259f55d687cca4 # Parent 0c05bdaeda343e437139e9f9901eeb3adea0aceb examples: relpipe-tr-sed diff -r 0c05bdaeda34 -r 4e45b9a177c2 relpipe-data/examples.xml --- a/relpipe-data/examples.xml Mon Dec 10 18:24:52 2018 +0100 +++ b/relpipe-data/examples.xml Mon Dec 10 19:43:48 2018 +0100 @@ -372,6 +372,74 @@

+

Rename VG in /etc/fstab using relpipe-tr-sed

+ +

+ Let's expect that we have a /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: +

+ + + +

+ Unlike the text-oriented sed command, the relational relpipe-tr-sed 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: +

+ + + +

+ 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. +

+ +

Using relpipe-tr-sed with groups and backreferences

+ +

+ This tool also support regex groups and backreferences. Thus we can use parts of the matched string in our replacement string: +

+ + + +

Which would convert this:

+
+ +

into this:

+
+ +

+ If there were any other relations or attributes in the stream, they would be unaffected by this transformation, + becase we specified 'r' 'a' instead of some wider regular expression that would match more relations or attributes. +

+