|
1 <stránka |
|
2 xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
|
3 xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
|
4 |
|
5 <nadpis>Changing values with AWK</nadpis> |
|
6 <perex>regular expression text replacement</perex> |
|
7 <m:pořadí-příkladu>02300</m:pořadí-příkladu> |
|
8 |
|
9 <text xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 <p> |
|
12 Besides filtering, we can use an AWK transformation to modify attribute values. |
|
13 This means simply rewriting the value of given variable in AWK and calling <code>record()</code> function at the end. |
|
14 </p> |
|
15 |
|
16 <p>For example we can move all volumes mounted under <code>/mnt/</code> to another directory using regular expressions:</p> |
|
17 |
|
18 <m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \ |
|
19 | relpipe-tr-awk \ |
|
20 --relation '.*' \ |
|
21 --for-each '{ mount_point = gensub("^/mnt/", "/mnt/old/", "g", mount_point); record(); }' \ |
|
22 | relpipe-out-tabular]]></m:pre> |
|
23 |
|
24 <p>which will result in:</p> |
|
25 |
|
26 <pre><![CDATA[fstab: |
|
27 ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬───────────────────────────────────────┬────────────────┬────────────────╮ |
|
28 │ scheme (string) │ device (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │ |
|
29 ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼───────────────────────────────────────┼────────────────┼────────────────┤ |
|
30 │ UUID │ 29758270-fd25-4a6c-a7bb-9a18302816af │ / │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 1 │ |
|
31 │ │ /dev/sr0 │ /media/cdrom0 │ udf,iso9660 │ user,noauto │ 0 │ 0 │ |
|
32 │ │ /dev/sde │ /mnt/old/data │ ext4 │ relatime,user_xattr,errors=remount-ro │ 0 │ 2 │ |
|
33 │ UUID │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home │ btrfs │ relatime │ 0 │ 2 │ |
|
34 │ │ /dev/mapper/sdf_crypt │ /mnt/old/private │ xfs │ relatime │ 0 │ 2 │ |
|
35 ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴───────────────────────────────────────┴────────────────┴────────────────╯ |
|
36 Record count: 5]]></pre> |
|
37 |
|
38 <p> |
|
39 We can modify multiple attributes in a single transformation |
|
40 and we can also use other AWK functions like <code>toupper()</code>, <code>tolower()</code> etc. |
|
41 </p> |
|
42 |
|
43 </text> |
|
44 |
|
45 </stránka> |