diff -r 9c1d0c5ed599 -r d4f401b5f90c relpipe-data/examples-out-bash.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-data/examples-out-bash.xml Tue Feb 05 19:18:28 2019 +0100 @@ -0,0 +1,65 @@ + + + Writing an output filter in Bash + processing relational data in GNU Bash or some other shell + 00600 + + + +

+ In previous example we created an output filter in Perl. + We converted a relation to values separated by \0 and then passed it through xargs to a perl one-liner (or a multi-liner in this case). + But we can write such output filter in pure Bash without xargs and perl. + Of course, it is still limited to a single relation (or it can process multiple relations of same type and do something like implicit UNION ALL). +

+ +

+ We will define a function that will help us with reading the \0-separated values and putting them into shell variables: +

+ + + + + +

+ Currently, there is no known way how to do this without a custom function (just with read built-in command of Bash and its parameters). + But it is just a single line function, so not a big deal. +

+ +

+ And then we just read the values, put them in shell variables and process them in a cycle in a shell block of code: +

+ + + +

+ Which will print: +

+ +
+ +

+ Using this method, we can convert any single relation to any format (preferably some text one, but printf can produce also binary data). + This is good for ad-hoc conversions and single-relation data. + More powerful tools can be written in C++ and other languages like Java, Python, Guile etc. (when particular libraries are available). +

+ +
+ +