diff -r a39066264509 -r 2868d772c27e relpipe-data/examples-awk-changing-structure.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-data/examples-awk-changing-structure.xml Tue May 28 21:18:20 2019 +0200 @@ -0,0 +1,112 @@ + + + Changing structures with AWK + adding or removing attributes or dropping a relation + 02400 + + + +

+ The AWK transformations can also change the structure of transformed relation. + It means adding or removing attributes or dropping the whole relation. +

+ +

Adding attributes with AWK

+ +

+ Using --output-attribute we can specify the output attributes. + If we do not want to explicitly specify all of them and just want to add some new ones, we will use --input-attributes-append (or --input-attributes-prepend), + which will preserve also the input attributes: +

+ + + +

This adds one new attribute with ordinal numbers:

+ +
+ + +

Remnoving attributes with AWK

+ +

Or we can omit omit attributes unless explicitly specified ones:

+ + + +

which effectively removes unlisted attributes:

+ +
+ + +

AWK is a powerful language so we can use conditions, for cycles etc. and write much more complex transformations.

+ +

Dropping a relation

+ +

+ A relation can be „dropped“ which means that transformation will run but no relational output will be generated for it + (even the header will be omitted, so it differs from just eliminating all records by a condition). + Using AWK for such a simple operation like DROP seems weird but sometimes it might make sense due to intentional side effects. +

+ +

+ Because the AWK code is executed for each record, we can e.g. write some output to a file or to STDERR: +

+ + "/dev/stderr" }' \ + --drop]]> + +

Which prints text:

+ +
+ +

+ Then relpipe-tr-awk works much like an output filter (converts relational data to another format). + However, if there are more relations and some of theme are not matched by --relation, they will be passed through and delivered to the STDOUT in the relational format. + STDERR might be occasionally polluted by some warning messages, so using a dedicated file for such output is a safer way. +

+ + +
+ +