relpipe-data/examples-awk-through-xml.xml
author František Kučera <franta-hg@frantovo.cz>
Mon, 21 Feb 2022 01:21:22 +0100
branchv_0
changeset 330 70e7eb578cfa
parent 288 5cf3a702f47d
permissions -rw-r--r--
Added tag relpipe-v0.18 for changeset 5bc2bb8b7946

<stránka
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
	
	<nadpis>AWKing through a XML file</nadpis>
	<perex>use AWK to filter data from a D-Bus policy file</perex>
	<m:pořadí-příkladu>03700</m:pořadí-příkladu>

	<text xmlns="http://www.w3.org/1999/xhtml">
		
		<p>
			The <a href="https://en.wikipedia.org/wiki/AWK">AWK</a> programming language and tool is designed for processing text
			but in <m:name/> we can use all the power of AWK for processing relational data that came from various sources.
			And „all the power“ means that we internally call the regular AWK implementation installed in our system (which is usually GNU AWK).
		</p>
		
		<p>
			In this example, we will read a D-Bus policy configuration file (an XML)
			and filter it using a simple AWK expression.
			The XML file looks like this:
		</p>
		
		<m:pre jazyk="xml" src="examples/awk-through-xml.xml"/>
		
		<p>
			We separate particular steps of our pipeline to shell functions for better readability and maintenance:
		</p>
	
		<m:pre jazyk="bash" src="examples/awk-through-xml.sh"/>
		
		<p>
			This simple sequence of steps will generate following result:
		</p>
		
		<m:pre jazyk="text" src="examples/awk-through-xml.txt"/>
		
		<p>
			We have processed two relations.
			One (<code>limit</code>) was just passed through
			while another (<code>policy</code>) was transformed.
			In this case, we did just restriction (filtered certain records), but we can do also projections or other relational operations in our pipelines.
		</p>
		
		<p>
			This example also shows how we can structure our scripts – compose the pipeline from reusable fragments (shell functions).
			Once we write the <em>parse</em> function for an input format, we can use it many times, with various filters/transformations and output formatters.
		</p>
		<p>
			Instead of converting to an output format, we can also <m:a href="examples-out-bash">execute arbitrary system commands</m:a> for each record 
			(while having particular attribute values reliably separated in shell variables).
		</p>
		
	</text>

</stránka>