examples: relpipe-tr-grep v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 10 Dec 2018 21:45:48 +0100
branchv_0
changeset 208 91a210d3b66a
parent 207 4e45b9a177c2
child 209 74fecc2ba590
examples: relpipe-tr-grep
relpipe-data/examples.xml
--- a/relpipe-data/examples.xml	Mon Dec 10 19:43:48 2018 +0100
+++ b/relpipe-data/examples.xml	Mon Dec 10 21:45:48 2018 +0100
@@ -383,7 +383,7 @@
 		
 		<p>
 			We want to change all lines from <code>alpha</code> to <code>beta</code> (the new VG name).
-			This can be done by:
+			This can be done by the power of regular expressions<m:podČarou>see <a href="https://en.wikibooks.org/wiki/Regular_Expressions/Simple_Regular_Expressions">Regular Expressions</a> at Wikibooks</m:podČarou> and this pipeline:
 		</p>
 		
 		<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \
@@ -440,6 +440,39 @@
 			becase we specified <code>'r' 'a'</code> instead of some wider regular expression that would match more relations or attributes.
 		</p>
 		
+		<h2>Filter /etc/fstab using relpipe-tr-grep</h2>
+		
+		<p>
+			If we are interested only in certain records in some relation, we can filter it using <code>relpipe-tr-grep</code>.
+			If we want to list e.g. only Btrfs and XFS file systems from our <code>fstab</code> (see above), we will run:
+		</p>
+		
+		
+		<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab | relpipe-tr-grep 'fstab' 'type' 'btrfs|xfs' | relpipe-out-tabular]]></m:pre>
+				
+		<p>and we will get following filtered result:</p>
+		<pre><![CDATA[fstab:
+ ╭─────────────────┬──────────────────────────────────────┬──────────────────────┬───────────────┬──────────────────┬────────────────┬────────────────╮
+ │ scheme (string) │ device                      (string) │ mount_point (string) │ type (string) │ options (string) │ dump (integer) │ pass (integer) │
+ ├─────────────────┼──────────────────────────────────────┼──────────────────────┼───────────────┼──────────────────┼────────────────┼────────────────┤
+ │ UUID            │ a2b5f230-a795-4f6f-a39b-9b57686c86d5 │ /home                │ btrfs         │ relatime         │              0 │              2 │
+ │                 │ /dev/mapper/sdf_crypt                │ /mnt/private         │ xfs           │ relatime         │              0 │              2 │
+ ╰─────────────────┴──────────────────────────────────────┴──────────────────────┴───────────────┴──────────────────┴────────────────┴────────────────╯
+Record count: 2]]></pre>
+
+		<p>
+			Command arguments are similar to <code>relpipe-tr-sed</code>.
+			Everything is a regular expression.
+			Only relations matching the regex will be filtered, others will flow through the pipeline unmodified.
+			If the attribute regex matches more attribute names, filtering will be done with logical OR
+			i.e. the record is included if at least one of that attributes matches the search regex.
+		</p>
+		
+		<p>
+			If we need exact match of the whole attribute, we have to use something like <code>'^btrfs|xfs$'</code>,
+			otherwise mere substring-match is enough to include the record.
+		</p>
+		
 	</text>
 
 </stránka>