relpipe-data/examples.xml
author František Kučera <franta-hg@frantovo.cz>
Thu, 06 Dec 2018 16:06:32 +0100
branchv_0
changeset 185 6cd2e54d90ea
parent 184 9ad44348e6aa
child 186 e33f13c91289
permissions -rw-r--r--
examples: relpipe-in-cli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     1
<stránka
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     4
	
140
1d8a3f7ec393 create empty pages
František Kučera <franta-hg@frantovo.cz>
parents: 139
diff changeset
     5
	<nadpis>Examples</nadpis>
1d8a3f7ec393 create empty pages
František Kučera <franta-hg@frantovo.cz>
parents: 139
diff changeset
     6
	<perex>Usage examples of Relational pipes tools</perex>
1d8a3f7ec393 create empty pages
František Kučera <franta-hg@frantovo.cz>
parents: 139
diff changeset
     7
	<pořadí>40</pořadí>
4
1bb39595a51c genrování hlavní nabídky #1
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     8
2
ab9099ff88fa vkládání zápatí, jmenné prostory, saxon
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
176
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
    10
		
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
    11
		
185
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    12
		<h3>relpipe-in-cli: Hello Wordl!</h3>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    13
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    14
		<p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    15
			Let's start with and obligatory Hello World example.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    16
		</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    17
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    18
		<m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    19
	"a" "integer" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    20
	"b" "string" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    21
	"c" "boolean" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    22
	"1" "Hello" "true" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    23
	"2" "World!" "false"]]></m:pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    24
	
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    25
		<p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    26
			This command generates relational data.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    27
			In order to see them, we need to convert them to some other format.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    28
			For now, we will use the "tabular" format and pipe relational data to the <code>relpipe-out-tabular</code>.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    29
		</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    30
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    31
		<m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    32
		"a" "integer" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    33
		"b" "string" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    34
		"c" "boolean" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    35
		"1" "Hello" "true" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    36
		"2" "World!" "false" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    37
	| relpipe-out-tabular]]></m:pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    38
	
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    39
		<p>Output:</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    40
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    41
		<pre><![CDATA[relation_from_cli:
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    42
 ╭─────────────┬────────────┬─────────────╮
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    43
 │ a (integer) │ b (string) │ c (boolean) │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    44
 ├─────────────┼────────────┼─────────────┤
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    45
 │           1 │ Hello      │        true │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    46
 │           2 │ World!     │       false │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    47
 ╰─────────────┴────────────┴─────────────╯
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    48
Record count: 2
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    49
]]></pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    50
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    51
		<p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    52
			The syntax is simple as we see above. We specify the name of the relation, number of attributes,
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    53
			and then their definitions (names and types),
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    54
			followed by the data.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    55
		</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    56
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    57
		<h3>relpipe-in-cli: STDIN</h3>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    58
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    59
		<p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    60
			The number of CLI arguments is limited and their are passed at once to the process.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    61
			So there is option to pass the values from STDIN instead of CLI arguments.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    62
			Values on STDIN are expected to be separated by the null-byte.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    63
			We can generate such data e.g. using <code>echo</code> and <code>tr</code> (or using <code>printf</code> or other commands):
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    64
		</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    65
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    66
		<m:pre jazyk="bash"><![CDATA[echo -e "1\nHello\ntrue\n2\nWorld\nfalse" \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    67
	| tr \\n \\0 \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    68
	| relpipe-in-cli generate-from-stdin relation_from_stdin 3 \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    69
		a integer \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    70
		b string \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    71
		c boolean \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    72
	| relpipe-out-tabular]]></m:pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    73
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    74
		<p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    75
			The output is same as above.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    76
			We can use this approach to convert various formats to relational data.
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    77
			There are lot of data already in the form of null-separated values e.g. the process arguments:
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    78
		</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    79
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    80
		<m:pre jazyk="bash"><![CDATA[cat /proc/$(pidof mc)/cmdline \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    81
	| relpipe-in-cli generate-from-stdin mc_args 1 a string \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    82
	| relpipe-out-tabular
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    83
]]></m:pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    84
	
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    85
		<p>If we have <code>mc /etc/ /tmp/</code> running in some other terminal, the output will be:</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    86
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    87
		<pre><![CDATA[mc_args:
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    88
 ╭────────────╮
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    89
 │ a (string) │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    90
 ├────────────┤
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    91
 │ mc         │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    92
 │ /etc/      │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    93
 │ /tmp/      │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    94
 ╰────────────╯
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    95
Record count: 3]]></pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    96
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    97
		<p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    98
			Also the <code>find</code> command can produce data separated by the null-byte:
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
    99
		</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   100
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   101
		<m:pre jazyk="bash"><![CDATA[find /etc/ -name '*ssh*_*' -print0 \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   102
	| relpipe-in-cli generate-from-stdin files 1 file_name string \
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   103
	| relpipe-out-tabular]]></m:pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   104
	
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   105
		<p>Will display something like this:</p>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   106
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   107
		<pre><![CDATA[files:
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   108
 ╭───────────────────────────────────╮
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   109
 │ file_name                (string) │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   110
 ├───────────────────────────────────┤
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   111
 │ /etc/ssh/ssh_host_ecdsa_key       │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   112
 │ /etc/ssh/sshd_config              │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   113
 │ /etc/ssh/ssh_host_ed25519_key.pub │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   114
 │ /etc/ssh/ssh_host_ecdsa_key.pub   │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   115
 │ /etc/ssh/ssh_host_rsa_key         │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   116
 │ /etc/ssh/ssh_config               │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   117
 │ /etc/ssh/ssh_host_ed25519_key     │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   118
 │ /etc/ssh/ssh_import_id            │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   119
 │ /etc/ssh/ssh_host_rsa_key.pub     │
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   120
 ╰───────────────────────────────────╯
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   121
Record count: 9]]></pre>
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   122
		
6cd2e54d90ea examples: relpipe-in-cli
František Kučera <franta-hg@frantovo.cz>
parents: 184
diff changeset
   123
		
176
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   124
		<h3>relpipe-tr-validator</h3>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   125
		
2
ab9099ff88fa vkládání zápatí, jmenné prostory, saxon
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   126
		<p>
176
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   127
			Just a passthrough command, so these pipelines should produce the same hash:
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   128
		</p>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   129
		
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   130
		<m:pre jazyk="bash"><![CDATA[
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   131
relpipe-in-fstab | relpipe-tr-validator | sha512sum
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   132
relpipe-in-fstab | sha512sum]]></m:pre>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   133
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   134
		<p>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   135
			This tool can be used for testing whether a file contains valid relational data:
87
25dec6931f18 Lepší odsazení, tabulátory.
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
   136
		</p>
176
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   137
		
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   138
		<m:pre jazyk="bash"><![CDATA[
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   139
if relpipe-tr-validator < "some-file.rp" &> /dev/null; then
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   140
	echo "valid relational data";
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   141
else
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   142
	echo "garbage";
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   143
fi]]></m:pre>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   144
		
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   145
		<p>or as a one-liner:</p>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   146
		
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   147
		<m:pre jazyk="bash"><![CDATA[relpipe-tr-validator < "some-file.rp" &> /dev/null && echo "ok" || echo "error"]]></m:pre>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   148
		
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   149
		<p>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   150
			If an error is found, it is reported on STDERR. So just omit the <code>&amp;</code> in order to see the error message.
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   151
		</p>
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
   152
		
180
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   153
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   154
		<h3>/etc/fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl</h3>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   155
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   156
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   157
			As we have seen before, we can convert <code>/etc/fstab</code> (or <code>mtab</code>)
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   158
			to e.g. an XML or a nice and colorful table using <m:name/>.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   159
			But we can also convert these data back to the <code>fstab</code> format. And do it with proper indentation/padding.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   160
			Fstab has a simple format where values are separated by one or more whitespace characters.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   161
			But without proper indentation, these files look a bit obfuscated and hard to read (however, they are valid).
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   162
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   163
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   164
		<m:pre jazyk="text" src="examples/relpipe-out-fstab.txt"/>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   165
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   166
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   167
			So let's build a pipeline that reformats the <code>fstab</code> and makes it more readable.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   168
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   169
			
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   170
		<m:pre jazyk="bash">relpipe-in-fstab | relpipe-out-fstab &gt; reformatted-fstab.txt</m:pre>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   171
			
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   172
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   173
			We can hack together a script called <code>relpipe-out-fstab</code> that accepts relational data and produces <code>fstab</code> data.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   174
			Later this will be probably implemented as a regular tool, but for now, it is just an example of a ad-hoc shell script:
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   175
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   176
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   177
		<m:pre jazyk="bash" src="examples/relpipe-out-fstab.sh" odkaz="ano"/>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   178
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   179
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   180
			In the first part, we prepend a single record (<code>relpipe-in-cli</code>) before the data coming from STDIN (<code>cat</code>).
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   181
			Then, we use <code>relpipe-out-nullbyte</code> to convert relational data to values separated by a null-byte.
184
9ad44348e6aa small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 180
diff changeset
   182
			This command processes only attribute values (skips relation and attribute names).
180
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   183
			Then we used <code>xargs</code> to read the null-separated values and execute a Perl command for each record (pass to it a same number of arguments, as we have attributes: <code>--max-args=7</code>).
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   184
			Perl does the actual formatting: adds padding and does some little tunning (merges two attributes and replaces empty values with <em>none</em>).
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   185
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   186
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   187
		<p>This is formatted version of the <code>fstab</code> above:</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   188
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   189
		<m:pre jazyk="text" src="examples/relpipe-out-fstab.formatted.txt"/>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   190
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   191
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   192
			And using following command we can verify, that the files differ only in comments and whitespace:
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   193
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   194
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   195
		<pre>relpipe-in-fstab | relpipe-out-fstab | diff -w /etc/fstab -</pre>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   196
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   197
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   198
			Regular implementation of <code>relpipe-out-fstab</code> will probably keep the comments
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   199
			(it needs also one more attribute and small change in <code>relpipe-in-fstab</code>).
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   200
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   201
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   202
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   203
			For just mere <code>fstab</code> reformatting, this approach is a bit overengineering.
184
9ad44348e6aa small fixes
František Kučera <franta-hg@frantovo.cz>
parents: 180
diff changeset
   204
			We could skip the whole relational thing and do just something like this:
180
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   205
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   206
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   207
		<m:pre jazyk="bash">cat /etc/fstab | grep -v '^#' | sed -E 's/\s+/\n/g' | tr \\n \\0 | xargs -0 -n7 ...</m:pre>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   208
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   209
		<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   210
			plus prepend the comment (or do everything in Perl).
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   211
			But this example is intended as a demostration, how we can
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   212
			1) prepend some additional data before the data from STDIN
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   213
			2) use <m:name/> and traditional tools like <code>xargs</code> or <code>perl</code> together.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   214
			And BTW we have implemented a (simple but working) <em>relpipe output filter</em> – and did it without any serious programming, just put some existing commands together :-)
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   215
		</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   216
		
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   217
		<blockquote>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   218
			<p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   219
				There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   220
				<m:podČarou>see <a href="http://www.catb.org/~esr/writings/unix-koans/ten-thousand.html">Master Foo and the Ten Thousand Lines</a></m:podČarou>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   221
			</p>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   222
		</blockquote>
d342de2e09a4 examples: fstab formatting using -in-fstab, -out-nullbyte, xargs and Perl
František Kučera <franta-hg@frantovo.cz>
parents: 176
diff changeset
   223
		
87
25dec6931f18 Lepší odsazení, tabulátory.
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
   224
	</text>
4
1bb39595a51c genrování hlavní nabídky #1
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
   225
1
a05c6f3cbc3e základ, první verze
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   226
</stránka>