# HG changeset patch
# User František Kučera
+ While reading classic pipelines involving grep
and cut
commands
+ we must notice that there is some similarity with simple SQL queries looking like:
+
+ And that is true: grep
does restrictioncut
does projectionrelpipe-tr-grep
and relpipe-tr-cut
.
+
+ Assume that we need only mount_point
fields from our fstab
where type
is btrfs
or xfs
+ and we want to do something (a shell script block) with these directory paths.
+
+ The relpipe-tr-cut
tool has similar syntax to its grep and sed siblings and also uses the power of regular expressions.
+ In this case it modifies on-the-fly the fstab
relation and drops all its attributes except the mount_point
one.
+
+ Then we pass the data to the Bash while cycle.
+ In such simple scenario (just echo
), we could use xargs
as in examples before,
+ but in this syntax, we can write whole block of shell commands for each record/value and do more complex actions with them.
+
+ Assume that we have a simple relation containing numbers: +
+ +and second one containing letters:
+ +We saved them into two files and then combined them into a single file. We will work with them as they are a single stream of relations:
+ +Will print:
+ + + +We can put away the a
attribute from the numbers
relation:
and leave the letters
relation unaffected:
Or we can remove a
from both relations resp. keep there only attributes whose names match 'b|c'
regex:
Instead of '.*'
we could use 'numbers|letters'
and in this case it will give the same result:
All the time, we are reducing the attributes. But we can also multiply them or change their order:
+ +
+ n.b. the order in 'b|a|c'
does not matter and if such regex matches, it preserves the original order of the attributes;
+ but if we specify multiple regexes to specify attributes, their order and count matters:
+
+ The letters
relation stays rock steady and relpipe-tr-cut 'numbers'
does not affect it in any way.
+