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