258
|
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>Using boolean logic with AWK</nadpis>
|
|
6 |
<perex>boolean data type and logical AND, OR, XOR operators</perex>
|
|
7 |
<m:pořadí-příkladu>02500</m:pořadí-příkladu>
|
|
8 |
|
|
9 |
<text xmlns="http://www.w3.org/1999/xhtml">
|
|
10 |
|
|
11 |
<p>Expect that we have a relation with four combinations of logical values:</p>
|
|
12 |
|
|
13 |
<pre><![CDATA[logic:
|
|
14 |
╭─────────────┬─────────────╮
|
|
15 |
│ a (boolean) │ b (boolean) │
|
|
16 |
├─────────────┼─────────────┤
|
|
17 |
│ true │ true │
|
|
18 |
│ true │ false │
|
|
19 |
│ false │ true │
|
|
20 |
│ false │ false │
|
|
21 |
╰─────────────┴─────────────╯
|
|
22 |
Record count: 4]]></pre>
|
|
23 |
|
|
24 |
<p>
|
|
25 |
we can use logical operators and functions:
|
|
26 |
</p>
|
|
27 |
|
|
28 |
|
|
29 |
<m:pre jazyk="bash"><![CDATA[relpipe-in-cli \
|
|
30 |
generate logic 2 \
|
|
31 |
a boolean \
|
|
32 |
b boolean \
|
|
33 |
true true \
|
|
34 |
true false \
|
|
35 |
false true \
|
|
36 |
false false \
|
|
37 |
| relpipe-tr-awk \
|
|
38 |
--relation '.*' \
|
|
39 |
--output-attribute AND boolean \
|
|
40 |
--output-attribute OR boolean \
|
|
41 |
--output-attribute XOR boolean \
|
|
42 |
--input-attributes-prepend \
|
|
43 |
--for-each '{ AND = a && b; OR = a || b; XOR = xor(a,b); record(); }' \
|
|
44 |
| relpipe-out-tabular]]></m:pre>
|
|
45 |
|
|
46 |
<p>and append their results to the relation as additional attributes:</p>
|
|
47 |
|
|
48 |
<pre><![CDATA[logic:
|
|
49 |
╭─────────────┬─────────────┬───────────────┬──────────────┬───────────────╮
|
|
50 |
│ a (boolean) │ b (boolean) │ AND (boolean) │ OR (boolean) │ XOR (boolean) │
|
|
51 |
├─────────────┼─────────────┼───────────────┼──────────────┼───────────────┤
|
|
52 |
│ true │ true │ true │ true │ false │
|
|
53 |
│ true │ false │ false │ true │ true │
|
|
54 |
│ false │ true │ false │ true │ true │
|
|
55 |
│ false │ false │ false │ false │ false │
|
|
56 |
╰─────────────┴─────────────┴───────────────┴──────────────┴───────────────╯
|
|
57 |
Record count: 4]]></pre>
|
|
58 |
|
|
59 |
</text>
|
|
60 |
|
|
61 |
</stránka>
|