Besides filtering, we can use an AWK transformation to modify attribute values.
This means simply rewriting the value of given variable in AWK and calling record()
function at the end.
For example we can move all volumes mounted under /mnt/
to another directory using regular expressions:
relpipe-in-fstab \
| relpipe-tr-awk \
--relation '.*' \
--for-each '{ mount_point = gensub("^/mnt/", "/mnt/old/", "g", mount_point); record(); }' \
| relpipe-out-tabular
which will result in:
fstab: ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮ │ scheme (string) │ device (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │ ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤ │ UUID │ 29758270-fd25-4a6c-a7bb-9a18302816af │ / │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 1 │ │ │ /dev/sr0 │ /media/cdrom0 │ udf,iso9660 │ user,noauto │ 0 │ 0 │ │ │ /dev/sde │ /mnt/old/data │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 2 │ │ UUID │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home │ btrfs │ relatime │ 0 │ 2 │ │ │ /dev/mapper/sdf_crypt │ /mnt/old/private │ xfs │ relatime │ 0 │ 2 │ ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯ Record count: 5
We can modify multiple attributes in a single transformation
and we can also use other AWK functions like toupper()
, tolower()
etc.
Relational pipes, open standard and free software © 2018-2022 GlobalCode