examples: improved Doing projection and restriction using cut and grep – add a chapter about CSV
--- a/relpipe-data/examples-grep-cut-fstab.xml Sat Jun 06 13:22:57 2020 +0200
+++ b/relpipe-data/examples-grep-cut-fstab.xml Mon Jun 08 12:34:16 2020 +0200
@@ -165,6 +165,59 @@
The <code>letters</code> relation stays rock steady and <code>relpipe-tr-cut 'numbers'</code> does not affect it in any way.
</p>
+ <h2>Process CSV files</h2>
+
+ <p>
+ There are various input filters (<code>relpipe-in-*</code>), one of them is <code>relpipe-in-csv</code>
+ which converts CSV files to relational format.
+ Thus we can process standard CSV files in our relational pipelines
+ and e.g. filter records that have certain value in certain column (<code>relpipe-tr-grep</code>)
+ or keep only certain columns (<code>relpipe-tr-cut</code>).
+ </p>
+
+ <p>
+ We may have a <code>tasks.csv</code> file containing TODOs and FIXMEs:
+ </p>
+
+ <pre><![CDATA["file","line","type","description"
+".hg/shelve-backup/posix_mq.patch","97","TODO","support also other encodings."
+".hg/shelve-backup/posix_mq.patch","163","TODO","support also other encodings."
+"src/FileAttributeFinder.h","79","TODO","optional whitespace trimming or substring"
+"src/FileAttributeFinder.h","80","TODO","custom encoding + read encoding from xattr"
+"src/FileAttributeFinder.h","83","TODO","allow custom error value or fallback to HEX/Base64"
+"streamlet-examples/streamlet-common.h","286","FIXME","correct error codes"
+…]]></pre>
+
+ <p>
+ And we can process it using this pipeline:
+ </p>
+
+ <m:pre jazyk="bash"><![CDATA[cat tasks.csv \
+ | relpipe-in-csv \
+ | relpipe-tr-grep 'csv' 'type' 'FIXME' \
+ | relpipe-tr-cut 'csv' 'file|description' \
+ | relpipe-out-tabular]]></m:pre>
+
+ <p>and get result like this:</p>
+
+ <pre><![CDATA[csv:
+ ╭───────────────────────────────────────┬──────────────────────╮
+ │ file (string) │ description (string) │
+ ├───────────────────────────────────────┼──────────────────────┤
+ │ streamlet-examples/streamlet-common.h │ correct error codes │
+ │ streamlet-examples/streamlet-common.h │ correct error codes │
+ │ streamlet-examples/Streamlet.java │ correct error codes │
+ ╰───────────────────────────────────────┴──────────────────────╯
+Record count: 3]]></pre>
+
+
+ <p>
+ We work with attribute (column) names, so there is no need to remember column numbers.
+ And thanks to regular expressions we can write elegant and powerful filters.
+ </p>
+
+
+
</text>
</stránka>