
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.thelinuxwiki.com/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Awk_reference</id>
		<title>Awk reference - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.thelinuxwiki.com/index.php?action=history&amp;feed=atom&amp;title=Awk_reference"/>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Awk_reference&amp;action=history"/>
		<updated>2026-04-29T02:43:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.21.5</generator>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Awk_reference&amp;diff=494&amp;oldid=prev</id>
		<title>Nighthawk at 14:03, 21 August 2013</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Awk_reference&amp;diff=494&amp;oldid=prev"/>
				<updated>2013-08-21T14:03:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 14:03, 21 August 2013&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; awk '{ i = NF-1; print $i }'&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; awk '{ i = NF-1; print $i }'&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; awk '{ i = NF-2; print $i }'&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; awk '{ i = NF-2; print $i }'&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== loop through fields from begging to end of line ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; awk -F &amp;quot;;&amp;quot; '{for (i=1; i&amp;lt;=NF; i++) print $i}'&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== read a particular line / record from file ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== read a particular line / record from file ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	<entry>
		<id>http://www.thelinuxwiki.com/index.php?title=Awk_reference&amp;diff=83&amp;oldid=prev</id>
		<title>Nighthawk: Pushed from thelinuxwiki.com.</title>
		<link rel="alternate" type="text/html" href="http://www.thelinuxwiki.com/index.php?title=Awk_reference&amp;diff=83&amp;oldid=prev"/>
				<updated>2013-02-25T19:02:00Z</updated>
		
		<summary type="html">&lt;p&gt;Pushed from thelinuxwiki.com.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== special varialbles ==&lt;br /&gt;
 NR is the number of records or lines&lt;br /&gt;
 NF is the number of fields in a line&lt;br /&gt;
&lt;br /&gt;
== printing from the END of a line ==&lt;br /&gt;
&lt;br /&gt;
printing the last word, next to last word, and 2nd from last word from a line respectively...&lt;br /&gt;
 awk '{ print $NF }'&lt;br /&gt;
 awk '{ i = NF-1; print $i }'&lt;br /&gt;
 awk '{ i = NF-2; print $i }'&lt;br /&gt;
&lt;br /&gt;
== read a particular line / record from file ==&lt;br /&gt;
&lt;br /&gt;
 awk &amp;quot;NR==$i&amp;quot; $FILENAME&lt;br /&gt;
example of above in variable assignment&lt;br /&gt;
 FOO=$(awk &amp;quot;NR==$i&amp;quot; $FILENAME)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== print all but a particular field or fields ==&lt;br /&gt;
&lt;br /&gt;
set field you want to exclude to null&lt;br /&gt;
 awk '{$1=&amp;quot;&amp;quot;; print }'&lt;br /&gt;
&lt;br /&gt;
== color formatted output ==&lt;br /&gt;
&lt;br /&gt;
To get color output from awk, you can use this approach.&lt;br /&gt;
&lt;br /&gt;
 function red(s) {&lt;br /&gt;
    printf &amp;quot;\033[1;31m&amp;quot; s &amp;quot;\033[0m &amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 function green(s) {&lt;br /&gt;
    printf &amp;quot;\033[1;32m&amp;quot; s &amp;quot;\033[0m &amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 function blue(s) {&lt;br /&gt;
    printf &amp;quot;\033[1;34m&amp;quot; s &amp;quot;\033[0m &amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     print red($1), green($2), blue($3)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
example one liner&lt;br /&gt;
 echo &amp;quot;red text is cool&amp;quot; | awk 'function red(s) {printf &amp;quot;\033[1;31m&amp;quot; s &amp;quot;\033[0m &amp;quot;} {print red($1) $2, $3, $4 }'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[category:dev]]&lt;/div&gt;</summary>
		<author><name>Nighthawk</name></author>	</entry>

	</feed>