<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Awk on Amit Agarwal Linux Blog</title>
    <link>/tags/awk/</link>
    <description>Recent content in Awk on Amit Agarwal Linux Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 29 Nov 2013 01:35:36 +0000</lastBuildDate>
    
	<atom:link href="/tags/awk/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Apache server stats with small and useful bash script.</title>
      <link>/2013/11/29/apache-server-stats-small-bash-script/</link>
      <pubDate>Fri, 29 Nov 2013 01:35:36 +0000</pubDate>
      
      <guid>/2013/11/29/apache-server-stats-small-bash-script/</guid>
      <description>&lt;p&gt;Just copy this script to your web-server &lt;a class=&#34;zem_slink&#34; title=&#34;Common Gateway Interface&#34; href=&#34;http://en.wikipedia.org/wiki/Common_Gateway_Interface&#34; target=&#34;_blank&#34; rel=&#34;wikipedia&#34;&gt;cgi-bin&lt;/a&gt; directory and enjoy.&lt;/p&gt;
&lt;p&gt;The script with show the common errors like &lt;a class=&#34;zem_slink&#34; title=&#34;HTTP 404&#34; href=&#34;http://en.wikipedia.org/wiki/HTTP_404&#34; target=&#34;_blank&#34; rel=&#34;wikipedia&#34;&gt;404 Error&lt;/a&gt;, &lt;a class=&#34;zem_slink&#34; title=&#34;List of HTTP status codes&#34; href=&#34;http://www.iana.org/assignments/http-status-codes&#34; target=&#34;_blank&#34; rel=&#34;homepage&#34;&gt;Internal Server Error&lt;/a&gt; and others. It will show the &lt;a class=&#34;zem_slink&#34; title=&#34;User agent&#34; href=&#34;http://en.wikipedia.org/wiki/User_agent&#34; target=&#34;_blank&#34; rel=&#34;wikipedia&#34;&gt;User agent&lt;/a&gt; distribution using simple commands like &lt;a class=&#34;zem_slink&#34; title=&#34;Grep&#34; href=&#34;http://en.wikipedia.org/wiki/Grep&#34; target=&#34;_blank&#34; rel=&#34;wikipedia&#34;&gt;grep&lt;/a&gt;, &lt;a class=&#34;zem_slink&#34; title=&#34;Uniq&#34; href=&#34;http://en.wikipedia.org/wiki/Uniq&#34; target=&#34;_blank&#34; rel=&#34;wikipedia&#34;&gt;uniq&lt;/a&gt;, &lt;a class=&#34;zem_slink&#34; title=&#34;AWK&#34; href=&#34;http://cm.bell-labs.com/cm/cs/awkbook&#34; target=&#34;_blank&#34; rel=&#34;homepage&#34;&gt;awk&lt;/a&gt; and so on.&lt;/p&gt;
&lt;p&gt;You would need to change the tfile – which is temporary file and also the access.log path in the next line.&lt;/p&gt;
&lt;p&gt;Just re-direct the output to some file with html extenstion. You could even put this in the cron which re-directs the output to some html in server document root.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>cvs add files recursively – not already in repository</title>
      <link>/2013/11/12/cvs-add-files-recursively-repository/</link>
      <pubDate>Tue, 12 Nov 2013 01:25:03 +0000</pubDate>
      
      <guid>/2013/11/12/cvs-add-files-recursively-repository/</guid>
      <description>&lt;p&gt;When you have a lot of files in some repository and you have added a couple of new, in &lt;a class=&#34;zem_slink&#34; title=&#34;Concurrent Versions System&#34; href=&#34;http://savannah.nongnu.org/projects/cvs&#34; target=&#34;_blank&#34; rel=&#34;homepage&#34;&gt;CVS&lt;/a&gt; there is no command to add just the new ones to the repository, so here is a workaround for that.&lt;/p&gt;
&lt;pre class=&#34;brush: actionscript3; gutter: true; first-line: 1&#34;&gt;cvs status 2&amp;gt;/dev/null | awk &#39;{if ($1==&#34;?&#34;)print &#34;cvs add -kb &#34; $2}&#39;&lt;/pre&gt;
&lt;p&gt;Well, if you are adding &lt;a class=&#34;zem_slink&#34; title=&#34;Text file&#34; href=&#34;http://en.wikipedia.org/wiki/Text_file&#34; target=&#34;_blank&#34; rel=&#34;wikipedia&#34;&gt;text files&lt;/a&gt; then you might want to remove the “-kB” in the cvs command above.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>BASH Script Performace</title>
      <link>/2012/01/06/bash-script-performace/</link>
      <pubDate>Fri, 06 Jan 2012 06:38:04 +0000</pubDate>
      
      <guid>/2012/01/06/bash-script-performace/</guid>
      <description>&lt;p&gt;Today we will look at some bash code snippests and the performance issues. Lets first look at the problem and the implemented solution:&lt;/p&gt;
&lt;p&gt;Problem: We needed to log the output of the ps command for all the process’s. This was required to be done on per minute basis and the output was required in comma separated files. So, here is what was implemented:&lt;/p&gt;
&lt;pre class=&#34;brush: bash; gutter: true; first-line: 1&#34;&gt;pslog=`ps -e -opid,ppid,user,nlwp,pmem,vsz,rss,s,time,stime,pri,nice,pcp:u,args|grep -v PID|sort -r -k 13,13`
        OLD_IFS=$IFS
        IFS=$&#39;\n&#39;
        logarr=( $pslog )
        for LOGLINE in ${logarr[@]}
        do
                LOGLINE=`echo $LOGLINE|awk &#39;{OFS=&#34;,&#34;;print $1,$2,$3,$4,$5,$6,$7,:$8,$9,$10,$11,$12,$13,$14}&#39;`
                echo $LOGLINE &amp;gt;&amp;gt; output
        done
        IFS=$OLD_IFS&lt;/pre&gt;
&lt;p&gt;This was working well and there were no issues. But suddenly we started seeing issues with the reported &lt;a class=&#34;zem_slink&#34; title=&#34;Central processing unit&#34; href=&#34;http://en.wikipedia.org/wiki/Central_processing_unit&#34; rel=&#34;wikipedia&#34;&gt;CPU&lt;/a&gt; usages. We would see that whenever this script was running the &lt;a class=&#34;zem_slink&#34; title=&#34;CPU time&#34; href=&#34;http://en.wikipedia.org/wiki/CPU_time&#34; rel=&#34;wikipedia&#34;&gt;CPU usage&lt;/a&gt; was high, specially if there were too many process’s/thread’s on the system during that time.  This code was definitely part of a very large &lt;a class=&#34;zem_slink&#34; title=&#34;Codebase&#34; href=&#34;http://en.wikipedia.org/wiki/Codebase&#34; rel=&#34;wikipedia&#34;&gt;code base&lt;/a&gt;, and at this point of time we did not know what was causing the issues.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Rekursive Grep on Solaris or AIX Systems without GNU egrep -r funcionality</title>
      <link>/2011/12/16/rekursive-grep-solaris-aix-systems-gnu-egrep-r-funcionality/</link>
      <pubDate>Fri, 16 Dec 2011 03:00:27 +0000</pubDate>
      
      <guid>/2011/12/16/rekursive-grep-solaris-aix-systems-gnu-egrep-r-funcionality/</guid>
      <description>&lt;p&gt;If you work regularly on a &lt;a class=&#34;zem_slink&#34; title=&#34;Solaris (operating system)&#34; href=&#34;http://oracle.com/solaris&#34; rel=&#34;homepage&#34;&gt;Solaris&lt;/a&gt; or systems which do not have the “-r” (recursive &lt;a class=&#34;zem_slink&#34; title=&#34;Grep&#34; href=&#34;http://en.wikipedia.org/wiki/Grep&#34; rel=&#34;wikipedia&#34;&gt;grep&lt;/a&gt;) for grep, then you know what a lifesaver this command can be.&lt;/p&gt;
&lt;p&gt;Here is one from &lt;a class=&#34;zem_slink&#34; title=&#34;Command-line interface&#34; href=&#34;http://en.wikipedia.org/wiki/Command-line_interface&#34; rel=&#34;wikipedia&#34;&gt;command line&lt;/a&gt; fu:&lt;/p&gt;
&lt;pre class=&#34;brush: bash; gutter: true; first-line: 1&#34;&gt;find . -type f -exec awk &#39;/linux/ { printf &#34;%s %s: %s\n&#34;, FILENAME, NR, $0; }&#39; {} \;&lt;/pre&gt;
&lt;p&gt;The benefit of using awk here is that you can print the line number also 🙂&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Linux hardware details.</title>
      <link>/2011/11/28/linux-hardware-details/</link>
      <pubDate>Mon, 28 Nov 2011 11:20:25 +0000</pubDate>
      
      <guid>/2011/11/28/linux-hardware-details/</guid>
      <description>&lt;p&gt;Here is one of the scripts that I found on the net while searching for something … Note the &lt;a class=&#34;zem_slink&#34; title=&#34;Uniform Resource Locator&#34; href=&#34;http://en.wikipedia.org/wiki/Uniform_Resource_Locator&#34; rel=&#34;wikipedia&#34;&gt;URL&lt;/a&gt; for the script in the Description.&lt;/p&gt;
&lt;pre class=&#34;brush: bash; gutter: true; first-line: 1&#34;&gt;#!/bin/bash -
#===============================================================================
#
#          FILE:  linux_hw.sh
#
#         USAGE:  ./linux_hw.sh
#
#   DESCRIPTION:  http://www.howtogeek.com/howto/solaris/get-the-processor-type-on-solaris/
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: &lt;a class=&#34;zem_slink&#34; title=&#34;Amit Agarwal&#34; href=&#34;http://www.labnol.org/about/&#34; rel=&#34;homepage&#34;&gt;Amit Agarwal&lt;/a&gt; (aka), amit.agarwal@roamware.com
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 09/13/2011 03:57:34 PM IST
# Last modified: Sun Oct 30, 2011  04:59PM
#      REVISION:  ---
#===============================================================================

function linux_hw_CPU {
	&lt;a class=&#34;zem_slink&#34; title=&#34;Typesetting&#34; href=&#34;http://en.wikipedia.org/wiki/Typesetting&#34; rel=&#34;wikipedia&#34;&gt;typeset&lt;/a&gt; num=0
	typeset name=&#34;&#34;
	typeset cores=&#34;&#34;
	name=&#34;$( cat &lt;a class=&#34;zem_slink&#34; title=&#34;Procfs&#34; href=&#34;http://en.wikipedia.org/wiki/Procfs&#34; rel=&#34;wikipedia&#34;&gt;/proc/cpuinfo&lt;/a&gt; | awk -F: &#39;
/vendor_id/ { vendor=$2 }
/model name/ { model=$2 }
/cpu &lt;a class=&#34;zem_slink&#34; title=&#34;Hertz&#34; href=&#34;http://en.wikipedia.org/wiki/Hertz&#34; rel=&#34;wikipedia&#34;&gt;MHz&lt;/a&gt;/ {
if( model ~ &#34;Hz&#34; ) {speed=&#34;&#34;} else { speed=$2? MHz&#34; };
print vendor, model, speed; }
		&#39; | tail -1
	)&#34;

        num=$(if [ -r /proc/vmware/cpuinfo ]; then awk &#39;/pcpu/ { print NF-1 }&#39; /proc/vmware/cpuinfo; else cat /proc/cpuinfo | &lt;a class=&#34;zem_slink&#34; title=&#34;Grep&#34; href=&#34;http://en.wikipedia.org/wiki/Grep&#34; rel=&#34;wikipedia&#34;&gt;grep&lt;/a&gt; processor| wc -l; fi)

	# ESX: mas info sobre logical/cores/packages
	if [ -r /proc/vmware/sched/ncpus ]
	then
		cores=$( echo $( cat /proc/vmware/sched/ncpus ) )
	fi

	echo $num $( echo &#34;$name ($cores)&#34; | enclose )
}

function enclose {
	tr -s &#34; &#34; | sed -e &#34;s/^/\&#34;/; s/$/\&#34;/; s/\&#34;\ /\&#34;/; s/\ \&#34;/\&#34;/&#34;
}

function linux_hw_CPU {

	typeset num=0
	typeset name=&#34;&#34;
	typeset cores=&#34;&#34;

	name=&#34;$(
		cat /proc/cpuinfo | awk -F: &#39;
/vendor_id/ { vendor=$2 }
/model name/ { model=$2 }
/cpu MHz/ {
if( model ~ &#34;Hz&#34; ) {speed=&#34;&#34;} else { speed=$2&#34; MHz&#34; };
print vendor, model, speed; }
		&#39; | tail -1
	)&#34;

	num=$(
		if [ -r /proc/vmware/cpuinfo ]
		then
			awk &#39;/pcpu/ { print NF-1 }&#39; /proc/vmware/cpuinfo
		else
			cat /proc/cpuinfo | grep processor| wc -l
		fi

	)

	if grep -q &#34;physical id&#34; /proc/cpuinfo || grep &#34;siblings&#34; /proc/cpuinfo
	then
		chip_count=$( grep &#34;physical id&#34; /proc/cpuinfo | sort -u | wc -l )
		chip_core=$( grep &#34;siblings&#34; /proc/cpuinfo | tail -1 | cut -d: -f2 )
		cores=&#34;($chip_count chips x $chip_core cores)&#34;
	fi

	# Blades HP con
	if [ -x /sbin/hpasmcli ]
	then
		chip_name=$( /sbin/hpasmcli -s &#34;SHOW &lt;a class=&#34;zem_slink&#34; title=&#34;Server (computing)&#34; href=&#34;http://en.wikipedia.org/wiki/Server_%28computing%29&#34; rel=&#34;wikipedia&#34;&gt;SERVER&lt;/a&gt;&#34; | grep &#34;Name&#34; | head -1 | cut -d: -f2 )
		chip_speed=$( /sbin/hpasmcli -s &#34;SHOW SERVER&#34; | grep &#34;Speed&#34; | head -1 | cut -d: -f2 )
		chip_core=$( /sbin/hpasmcli -s &#34;SHOW SERVER&#34; | grep &#34;Core&#34; | head -1 | cut -d: -f2 )
	fi

	# ESX: mas info sobre logical/cores/packages
	if [ -r /proc/vmware/sched/ncpus ]
	then
		cores=&#34;($( echo $( cat /proc/vmware/sched/ncpus ) ))&#34;
	fi

	# &lt;a class=&#34;zem_slink&#34; title=&#34;Linux&#34; href=&#34;http://www.kernel.org/&#34; rel=&#34;homepage&#34;&gt;Linux&lt;/a&gt; &lt;a class=&#34;zem_slink&#34; title=&#34;Itanium&#34; href=&#34;http://en.wikipedia.org/wiki/Itanium&#34; rel=&#34;wikipedia&#34;&gt;Itanium&lt;/a&gt; IA64
	if grep -q -i itanium /proc/cpuinfo
	then
		name=&#34;$(
		grep &#34;vendor&#34; /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep &#34;arch &#34; /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep &#34;family&#34; /proc/cpuinfo | cut -d: -f2- | tail -1 ) $(
		grep &#34;cpu MHz&#34; /proc/cpuinfo | cut -d: -f2- | cut -d. -f1 | tail -1 ) Mhz&#34;

		chip_count=$( grep &#34;physical id&#34; /proc/cpuinfo | sort -u | wc -l )
		chip_core=$( grep &#34;siblings&#34; /proc/cpuinfo | tail -1 | cut -d: -f2 )
		cores=&#34;($chip_count chips x $chip_core cores)&#34;
	fi

	echo $num $( echo &#34;$name $cores&#34; | enclose )
}

linux_hw_CPU&lt;/pre&gt;
&lt;h6 class=&#34;zemanta-related-title&#34; style=&#34;font-size: 1em;&#34;&gt;
  Related articles
&lt;/h6&gt;
&lt;ul class=&#34;zemanta-article-ul&#34;&gt;
  &lt;li class=&#34;zemanta-article-ul-li&#34;&gt;
    &lt;a href=&#34;http://weijianhui16.wordpress.com/2011/09/06/linux%e6%9f%a5%e7%9c%8b%e7%a1%ac%e4%bb%b6%e4%bf%a1%e6%81%af/&#34;&gt;linux??????&lt;/a&gt; (weijianhui16.wordpress.com)
  &lt;/li&gt;
  &lt;li class=&#34;zemanta-article-ul-li&#34;&gt;
    &lt;a href=&#34;http://singztechmusings.wordpress.com/2011/06/15/how-to-check-the-uptime-of-a-process-or-an-application-running-in-linux-machine-using-shell-script/&#34;&gt;How to check the uptime of a process (or an application) running in Linux machine using shell script?&lt;/a&gt; (singztechmusings.wordpress.com)
  &lt;/li&gt;
  &lt;li class=&#34;zemanta-article-ul-li&#34;&gt;
    &lt;a href=&#34;http://javarevisited.wordpress.com/2011/06/15/good-examples-of-grep-command-in-unix-and-linux/&#34;&gt;Some examples of grep command in unix&lt;/a&gt; (javarevisited.wordpress.com)
  &lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;zemanta-pixie&#34; style=&#34;margin-top: 10px; height: 15px;&#34;&gt;
  &lt;a class=&#34;zemanta-pixie-a&#34; title=&#34;Enhanced by Zemanta&#34; href=&#34;http://www.zemanta.com/&#34;&gt;&lt;img class=&#34;zemanta-pixie-img&#34; style=&#34;float: right;&#34; src=&#34;https://i1.wp.com/img.zemanta.com/zemified_e.png?w=688&#34; alt=&#34;Enhanced by Zemanta&#34; data-recalc-dims=&#34;1&#34; /&gt;&lt;/a&gt;
&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Total upload and download on any interface.</title>
      <link>/2011/06/05/total-upload-download-interface/</link>
      <pubDate>Sun, 05 Jun 2011 01:29:21 +0000</pubDate>
      
      <guid>/2011/06/05/total-upload-download-interface/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Something that I have been searching for a long time, finally some look inside the &amp;lt;a class=&amp;ldquo;zem_slink&amp;rdquo; title=&amp;ldquo;Procfs&amp;rdquo; rel=&amp;ldquo;wikipedia&amp;rdquo; href=&amp;ldquo;&lt;a href=&#34;http://en.wikipedia.org/wiki/Procfs%22&#34;&gt;http://en.wikipedia.org/wiki/Procfs&amp;quot;&lt;/a&gt; _mce_href=&amp;ldquo;&lt;a href=&#34;http://en.wikipedia.org/wiki/Procfs%22%3E/proc&#34;&gt;http://en.wikipedia.org/wiki/Procfs&amp;quot;&amp;gt;/proc&lt;/a&gt;&lt;/a&gt; got me what I wanted. Hope this will save someone’s day. So far, the only option I could think of was to run conky which becomes a little heave on some of the very old laptops I have to use sometimes 🙁&lt;/p&gt;
&lt;div class=&#34;codecolorer-container text solarized-light&#34; style=&#34;overflow:auto;white-space:nowrap;width:550px;&#34;&gt;
  &lt;table cellspacing=&#34;0&#34; cellpadding=&#34;0&#34;&gt;
    &lt;tr&gt;
      &lt;td class=&#34;line-numbers&#34;&gt;
        &lt;div&gt;
          1&lt;br /&gt;
        &lt;/div&gt;
      &lt;/td&gt;
&lt;pre&gt;&lt;code&gt;  &amp;lt;td&amp;gt;
    &amp;lt;div class=&amp;quot;text codecolorer&amp;quot;&amp;gt;
      &amp;amp;nbsp;cat /proc/net/dev|grep eth2|awk &#39;{print $2/1024/1024&amp;quot;&amp;amp;nbsp; &amp;quot;$10/1024/1024}&#39;
    &amp;lt;/div&amp;gt;
  &amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
  &lt;/table&gt;
&lt;/div&gt;&lt;h6 class=&#34;zemanta-related-title&#34; style=&#34;font-size: 1em;&#34; \_mce\_style=&#34;font-size: 1em;&#34;&gt;Related articles&lt;/h6&gt; 
&lt;ul class=&#34;zemanta-article-ul&#34;&gt;
  &lt;li class=&#34;zemanta-article-ul-li&#34;&gt;
    &lt;a href=&#34;http://jarneil.wordpress.com/2011/03/15/cpuspeed-slowing-you-down/&#34; _mce_href=&#34;http://jarneil.wordpress.com/2011/03/15/cpuspeed-slowing-you-down/&#34;&gt;CPUSPEED Slowing you down?&lt;/a&gt; (jarneil.wordpress.com)
  &lt;/li&gt;
  &lt;li class=&#34;zemanta-article-ul-li&#34;&gt;
    &lt;a href=&#34;http://lingpipe-blog.com/2011/05/26/interface-curmudgeons/&#34; _mce_href=&#34;http://lingpipe-blog.com/2011/05/26/interface-curmudgeons/&#34;&gt;Interface Curmudgeons versus Gestures&lt;/a&gt; (lingpipe-blog.com)
  &lt;/li&gt;
  &lt;li class=&#34;zemanta-article-ul-li&#34;&gt;
    &lt;a href=&#34;http://michaeldaranto.wordpress.com/2011/05/28/alias-in-bashrc/&#34; _mce_href=&#34;http://michaeldaranto.wordpress.com/2011/05/28/alias-in-bashrc/&#34;&gt;Alias in .bashrc&lt;/a&gt; (michaeldaranto.wordpress.com)
  &lt;/li&gt;
&lt;/ul&gt;&lt;div class=&#34;zemanta-pixie&#34; style=&#34;margin-top: 10px; height: 15px;&#34; \_mce\_style=&#34;margin-top: 10px; height: 15px;&#34;&gt;&lt;a class=&#34;zemanta-pixie-a&#34; title=&#34;Enhanced by Zemanta&#34; href=&#34;http://www.zemanta.com/&#34; \_mce\_href=&#34;http://www.zemanta.com/&#34;&gt;&lt;img class=&#34;zemanta-pixie-img&#34; style=&#34;border: medium none; float: right;&#34; \_mce\_style=&#34;border: medium none; float: right;&#34; src=&#34;https://i1.wp.com/img.zemanta.com/zemified\_e.png?w=688&#34; \_mce\_src=&#34;https://i1.wp.com/img.zemanta.com/zemified\_e.png?w=688&#34; alt=&#34;Enhanced by Zemanta&#34; data-recalc-dims=&#34;1&#34;/&gt;&lt;/a&gt;&lt;br \_mce\_bogus=&#34;1&#34;/&gt;&lt;/div&gt;</description>
    </item>
    
    <item>
      <title>Ranking of the most frequently used commands</title>
      <link>/2011/02/01/ranking-frequently-commands/</link>
      <pubDate>Mon, 31 Jan 2011 22:54:43 +0000</pubDate>
      
      <guid>/2011/02/01/ranking-frequently-commands/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Lets take a quick look at how to get the most frequently used commands on you shell. So what we need to do is this:&lt;/p&gt;
&lt;div class=&#34;codecolorer-container text solarized-light&#34; style=&#34;overflow:auto;white-space:nowrap;width:550px;&#34;&gt;
  &lt;table cellspacing=&#34;0&#34; cellpadding=&#34;0&#34;&gt;
    &lt;tr&gt;
      &lt;td class=&#34;line-numbers&#34;&gt;
        &lt;div&gt;
          1&lt;br /&gt;
        &lt;/div&gt;
      &lt;/td&gt;
&lt;pre&gt;&lt;code&gt;  &amp;lt;td&amp;gt;
    &amp;lt;div class=&amp;quot;text codecolorer&amp;quot;&amp;gt;
      history | awk &#39;{print $2}&#39; | awk &#39;BEGIN {FS=&amp;quot;|&amp;quot;}{print $1}&#39; | sort | uniq -c | sort -n | tail | sort -nr
    &amp;lt;/div&amp;gt;
  &amp;lt;/td&amp;gt;
&amp;lt;/tr&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
  &lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;So, how did we arrive at this and will this always work? No it might not always work. A typical example is where HISTTIMEFORMAT variable is set. In that case, if you check history, you will see that after the number column we have &lt;a class=&#34;zem_slink&#34; title=&#34;Time and date&#34; rel=&#34;wikipedia&#34; href=&#34;http://en.wikipedia.org/wiki/Time_and_date&#34;&gt;time and date&lt;/a&gt; in the specified format, in which case, you will get wrong information from the above command. Anyways, forgetting these special cases, lets go to how we got this command:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>List of commands you use most often</title>
      <link>/2010/07/25/list-of-commands-you-use-most-often/</link>
      <pubDate>Sun, 25 Jul 2010 03:53:08 +0000</pubDate>
      
      <guid>/2010/07/25/list-of-commands-you-use-most-often/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;&lt;tt&gt;$ history | &amp;lt;a class=&amp;quot;zem_slink&amp;quot; title=&amp;quot;AWK&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://cm.bell-labs.com/cm/cs/awkbook/index.html&amp;quot;&amp;gt;awk&lt;/a&gt; &#39;{a[$2]++}END{for(i in a){print a[i] &amp;quot; &amp;quot; i}}&#39; | sort -rn | head &amp;gt; /tmp/cmds | &amp;lt;a class=&amp;quot;zem_slink&amp;quot; title=&amp;quot;Gnuplot&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://www.gnuplot.info/&amp;quot;&amp;gt;gnuplot&lt;/a&gt; -persist &amp;lt;(echo &#39;plot &amp;quot;/tmp/cmds&amp;quot; using 1:xticlabels(2) with boxes&#39;)&lt;/tt&gt; Plot your most used commands with gnuplot.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;lt;a href=&amp;quot;http://www.commandlinefu.com/commands/view/5845/list-of-commands-you-use-most-often&amp;quot;&amp;gt;View this command to comment, vote or add to favourites&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;lt;a href=&amp;quot;http://feeds2.feedburner.com/commands/by/sthrs&amp;quot;&amp;gt;View all commands by &lt;/a&gt;&lt;strong&gt;&amp;lt;a href=&amp;quot;http://feeds2.feedburner.com/commands/by/sthrs&amp;quot;&amp;gt;sthrs&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;lt;a href=&amp;quot;http://www.commandlinefu.com&amp;quot;&amp;gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;by David Winterbottom (&amp;lt;a href=&amp;quot;http://codeinthehole.com&amp;quot;&amp;gt;codeinthehole.com&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&amp;lt;a href=&amp;quot;http://feedads.g.doubleclick.net/~a/qns5iNy&amp;ndash;6jXLRCLFY_jGnkB68s/0/da&amp;quot;&amp;gt;&lt;/a&gt;&lt;br&gt;
&amp;lt;a href=&amp;quot;http://feedads.g.doubleclick.net/~a/qns5iNy&amp;ndash;6jXLRCLFY_jGnkB68s/1/da&amp;quot;&amp;gt;&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>concatenate compressed and uncompressed logs</title>
      <link>/2010/07/15/concatenate-compressed-and-uncompressed-logs/</link>
      <pubDate>Thu, 15 Jul 2010 02:10:28 +0000</pubDate>
      
      <guid>/2010/07/15/concatenate-compressed-and-uncompressed-logs/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;h1 id=&#34;span-stylefont-size-x-largea-hrefhttpfeedproxygooglecomrcommand-line-fu3iwfuyltygjmconcatenate-compressed-and-uncompressed-logsconcatenate-compressed-and-uncompressed-logsaspan&#34;&gt;&lt;strong&gt;&amp;lt;span style=&amp;quot;font-size: x-large;&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;http://feedproxy.google.com/~r/Command-line-fu/~3/iwFUyltYgjM/concatenate-compressed-and-uncompressed-logs&amp;quot;&amp;gt;concatenate compressed and uncompressed logs&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/h1&gt;
&lt;p&gt;&lt;tt&gt;$ find /var/log/apache2 -name &#39;access.log&lt;em&gt;gz&#39; -exec &amp;lt;a class=&amp;quot;zem_slink freebase/guid/9202a8c04000641f800000000001abd9&amp;quot; title=&amp;quot;Gzip&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://www.gzip.org/&amp;quot;&amp;gt;zcat&lt;/a&gt; {} ; -or -name &#39;access.log&lt;/em&gt;&#39; -exec cat {} ;&lt;/tt&gt; This command allows you to stream your log files, including gziped files, into one stream which can be piped to &amp;lt;a class=&amp;quot;zem_slink freebase/guid/9202a8c04000641f800000000000584b&amp;quot; title=&amp;quot;AWK&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://cm.bell-labs.com/cm/cs/awkbook/index.html&amp;quot;&amp;gt;awk&lt;/a&gt; or some other command for analysis.&lt;/p&gt;
&lt;p&gt;Note: if your version of &amp;amp;#8217;find&amp;amp;#8217; supports it, use:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>List of commands you use most often</title>
      <link>/2010/06/16/list-commands/</link>
      <pubDate>Wed, 16 Jun 2010 02:17:01 +0000</pubDate>
      
      <guid>/2010/06/16/list-commands/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;h1 id=&#34;span-stylefont-size-x-largea-hrefhttpfeedproxygooglecomrcommand-line-fu36mxhisiindolist-of-commands-you-use-most-oftenlist-of-commands-you-use-most-oftenaspan&#34;&gt;&lt;strong&gt;&amp;lt;span style=&amp;quot;font-size: x-large;&amp;quot;&amp;gt;&amp;lt;a href=&amp;quot;http://feedproxy.google.com/~r/Command-line-fu/~3/6MxHiSiINdo/list-of-commands-you-use-most-often&amp;quot;&amp;gt;List of commands you use most often&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/h1&gt;
&lt;p&gt;&lt;tt&gt;$ history | &amp;lt;a class=&amp;quot;zem_slink freebase/en/awk&amp;quot; title=&amp;quot;AWK&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://cm.bell-labs.com/cm/cs/awkbook/index.html&amp;quot;&amp;gt;awk&lt;/a&gt; &#39;{a[$2]++}END{for(i in a){print a[i] &amp;quot; &amp;quot; i}}&#39; | sort -rn | head &amp;gt; /tmp/cmds | gnuplot -persist &amp;lt;(echo &#39;plot &amp;quot;/tmp/cmds&amp;quot; using 1:xticlabels(2) with boxes&#39;)&lt;/tt&gt; Plot your most used commands with gnuplot.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;lt;a href=&amp;quot;http://www.commandlinefu.com/commands/view/5845/list-of-commands-you-use-most-often&amp;quot;&amp;gt;View this command to comment, vote or add to favourites&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&amp;lt;a href=&amp;quot;http://feeds2.feedburner.com/commands/by/sthrs&amp;quot;&amp;gt;View all commands by &lt;/a&gt;&lt;strong&gt;&amp;lt;a href=&amp;quot;http://feeds2.feedburner.com/commands/by/sthrs&amp;quot;&amp;gt;sthrs&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;lt;a href=&amp;quot;http://www.commandlinefu.com&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg&amp;quot; alt=&amp;quot;commandlinefu.com&amp;quot; align=&amp;quot;bottom&amp;quot; /&amp;gt;&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Determine what process is listening on a port on Solaris, without lsof</title>
      <link>/2010/06/08/determine-what-process-is-listening-on-a-port-on-solaris-without-lsof/</link>
      <pubDate>Tue, 08 Jun 2010 09:13:37 +0000</pubDate>
      
      <guid>/2010/06/08/determine-what-process-is-listening-on-a-port-on-solaris-without-lsof/</guid>
      <description>&lt;div class=\&#34;zemanta-img\&#34;&gt; 
&lt;div&gt;
  &lt;dl class=\&#34;wp-caption alignright\&#34;&gt; &lt;dt class=\&#34;wp-caption-dt\&#34;&gt;&lt;a href=\&#34;http://www.flickr.com/photos/24543279@N04/3913703678\&#34;&gt;&lt;img title=\&#34;Desktop September 2009 (Mac)\&#34; src=\&#34;http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/3913703678_a6912b45d0_m.jpg\&#34; alt=\&#34;Desktop September 2009 (Mac)\&#34; /&gt;&lt;/a&gt;&lt;/dt&gt; &lt;dd class=\&#34;wp-caption-dd zemanta-img-attribution\&#34;&gt;Image by &lt;a href=\&#34;http://www.flickr.com/photos/24543279@N04/3913703678\&#34;&gt;Metsuke iLife&lt;/a&gt; via Flickr&lt;/dd&gt; &lt;/dl&gt;
&lt;/div&gt;&lt;/div&gt; 
&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;$ for x in `ptree | &amp;lt;a class=&amp;quot;zem_slink freebase/en/awk&amp;quot; title=&amp;quot;AWK&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://cm.bell-labs.com/cm/cs/awkbook/index.html&amp;quot;&amp;gt;awk&lt;/a&gt; &#39;{print $1}&amp;amp;#8217;`; do pfiles $x | &amp;lt;a class=&amp;quot;zem_slink freebase/en/grep&amp;quot; title=&amp;quot;Grep&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/Grep&amp;quot;&amp;gt;grep&lt;/a&gt; ${PORT} &amp;gt; /dev/null 2&amp;gt;&amp;amp;1; if [ x&amp;amp;#8221;$?&amp;amp;#8221; == &amp;amp;#8221;x0&amp;amp;#8221; ]; then ps -ef | grep $x | grep -v grep; fi; done 2&amp;gt; /dev/null&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>redet – build regular expression (regex) for any program.</title>
      <link>/2010/06/04/redet-build-regular-expression-regex-for-any-program/</link>
      <pubDate>Fri, 04 Jun 2010 02:06:46 +0000</pubDate>
      
      <guid>/2010/06/04/redet-build-regular-expression-regex-for-any-program/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Even if someone is  a regex guru there are times that people get confused with some regular expression and want to either test it out or want to some help. Behold, redet is here. Lets start with installing redet:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;sudo yum install redet&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Once you are done with installation, just run it with redet. First you need to load the sample data, select your program and then enter the regex to test it out. Here are some screenshots to get you started.&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Awk Introduction Tutorial – 7 Awk Print Examples</title>
      <link>/2010/05/19/awk-introduction-tutorial-%E2%80%93-7-awk-print-examples/</link>
      <pubDate>Wed, 19 May 2010 16:38:43 +0000</pubDate>
      
      <guid>/2010/05/19/awk-introduction-tutorial-%E2%80%93-7-awk-print-examples/</guid>
      <description>&lt;div class=\&#34;zemanta-img\&#34;&gt; 
&lt;div&gt;
  &lt;dl class=\&#34;wp-caption alignright\&#34;&gt; &lt;dt class=\&#34;wp-caption-dt\&#34;&gt;&lt;a href=\&#34;http://www.daylife.com/image/0fNM7HH9s1904?utm_source=zemanta&amp;utm_medium=p&amp;utm_content=0fNM7HH9s1904&amp;utm_campaign=z1\&#34;&gt;&lt;img title=\&#34;LAS VEGAS - JANUARY 23: Dick Robertson, Presi...\&#34; src=\&#34;http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/150x104.jpg\&#34; alt=\&#34;LAS VEGAS - JANUARY 23: Dick Robertson, Presi...\&#34; /&gt;&lt;/a&gt;&lt;/dt&gt; &lt;dd class=\&#34;wp-caption-dd zemanta-img-attribution\&#34;&gt;Image by &lt;a href=\&#34;http://www.daylife.com/source/Getty_Images\&#34;&gt;Getty Images&lt;/a&gt; via &lt;a href=\&#34;http://www.daylife.com\&#34;&gt;Daylife&lt;/a&gt;&lt;/dd&gt; &lt;/dl&gt;
&lt;/div&gt;&lt;/div&gt; 
&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;awk examples&lt;/p&gt;
&lt;p&gt;Awk Introduction Tutorial – 7 Awk Print Examples This is the first article on the new awk tutorial series. We’ll be posting several articles on awk in the upcoming weeks that will cover all features of awk with practical examples. In this article, let us review the fundamental awk working methodology along with 7 practical awk print examples. Note: Make sure you review our earlier […]&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Splitting strings with IFS</title>
      <link>/2010/02/04/splitting-strings-with-ifs/</link>
      <pubDate>Thu, 04 Feb 2010 15:58:43 +0000</pubDate>
      
      <guid>/2010/02/04/splitting-strings-with-ifs/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Today I want to discuss splitting strings into tokens or “words”. I previously discussed how to do this with the &amp;lt;a href=&amp;quot;http://bashcurescancer.com/reading-a-file-line-by-line.html&amp;quot;&amp;gt;IFS variable&lt;/a&gt; and promised a more in depth discussion. Today, I will make the case on WHY to use IFS to split strings as opposed to using a subshell combined with &amp;lt;a class=&amp;quot;zem_slink freebase/en/awk&amp;quot; title=&amp;quot;AWK&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://cm.bell-labs.com/cm/cs/awkbook/index.html&amp;quot;&amp;gt;awk&lt;/a&gt; or cut.&lt;/p&gt;
&lt;p&gt;I wrote this script which reads the /etc/password file line-by-line and prints the &amp;lt;a class=&amp;quot;zem_slink freebase/en/user&amp;quot; title=&amp;quot;User (computing)&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/User_%28computing%29&amp;quot;&amp;gt;username&lt;/a&gt; of any user which has a UID greater than 10 and has the shell of /sbin/nologin. Each test function performs this task 10 times to increase the length of the test:&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Understand Awk Variables with 3 Practical Examples</title>
      <link>/2010/01/28/understand-awk-variables-with-3-practical-examples/</link>
      <pubDate>Thu, 28 Jan 2010 08:02:21 +0000</pubDate>
      
      <guid>/2010/01/28/understand-awk-variables-with-3-practical-examples/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;&amp;lt;a id=&amp;quot;aptureLink_gQhJKQ92Kn&amp;quot; style=&amp;quot;padding: 0px 6px; float: left;&amp;quot; href=&amp;quot;http://www.gnu.org/software/gawk/manual/gawk.html&amp;quot;&amp;gt;&amp;lt;img style=&amp;quot;border: 0px none;&amp;quot; title=&amp;quot;The GNU Awk User&#39;s Guide&amp;quot; src=&amp;quot;http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/ph/400x270_WebClip&amp;quot; alt=&amp;quot;&amp;quot; width=&amp;quot;400px&amp;quot; height=&amp;quot;270px&amp;quot; /&amp;gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;a id=&amp;quot;aptureLink_CLV4LbC1Dr&amp;quot; style=&amp;quot;padding: 0px 6px; float: right;&amp;quot; href=&amp;quot;http://gnuwin32.sourceforge.net/packages/mawk.htm&amp;quot;&amp;gt;&amp;lt;img style=&amp;quot;border: 0px none;&amp;quot; title=&amp;quot;Mawk for Windows&amp;quot; src=&amp;quot;http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/ph/400x270_WebClip&amp;quot; alt=&amp;quot;&amp;quot; width=&amp;quot;400px&amp;quot; height=&amp;quot;270px&amp;quot; /&amp;gt;&lt;/a&gt; This article is part of the on-going Awk Tutorial and Examples series. Like any other &amp;lt;a class=&amp;quot;zem_slink freebase/en/programming_language&amp;quot; title=&amp;quot;Programming language&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/Programming_language&amp;quot;&amp;gt;programming languages&lt;/a&gt;, Awk also has user defined variables and built-in variables. In this article let us review how to define and use &amp;lt;a class=&amp;quot;zem_slink freebase/en/awk&amp;quot; title=&amp;quot;AWK&amp;quot; rel=&amp;quot;homepage&amp;quot; href=&amp;quot;http://cm.bell-labs.com/cm/cs/awkbook/index.html&amp;quot;&amp;gt;awk&lt;/a&gt; variables. Awk variables should begin with the letter, followed by it can consist of alpha numeric characters or underscore. Keywords […]&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Display the output of a command from the first line until the first instance of a regular expression.</title>
      <link>/2010/01/05/display-the-output-of-a-command-from-the-first-line-until-the-first-instance-of-a-regular-expression/</link>
      <pubDate>Mon, 04 Jan 2010 22:46:55 +0000</pubDate>
      
      <guid>/2010/01/05/display-the-output-of-a-command-from-the-first-line-until-the-first-instance-of-a-regular-expression/</guid>
      <description>&lt;div class=\&#34;zemanta-img\&#34;&gt; 
&lt;div&gt;
  &lt;dl class=\&#34;wp-caption alignright\&#34;&gt; &lt;dt class=\&#34;wp-caption-dt\&#34;&gt;&lt;a href=\&#34;http://blog.amit-agarwal.co.in/wp-content/uploads/2010/01/Image:Bash_screenshot.png\&#34;&gt;&lt;img title=\&#34;Screenshot of a sample Bash session.\&#34; src=\&#34;http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/300px-Bash_screenshot.png\&#34; alt=\&#34;Screenshot of a sample Bash session.\&#34; /&gt;&lt;/a&gt;&lt;/dt&gt; &lt;dd class=\&#34;wp-caption-dd zemanta-img-attribution\&#34;&gt;Image via &lt;a href=\&#34;http://blog.amit-agarwal.co.in/wp-content/uploads/2010/01/Image:Bash_screenshot.png\&#34;&gt;Wikipedia&lt;/a&gt;&lt;/dd&gt; &lt;/dl&gt;
&lt;/div&gt;&lt;/div&gt; 
&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;&lt;tt&gt;| perl -n -e &#39;print &amp;quot;$_&amp;quot; if 1 &amp;hellip; /&amp;laquo;a class=&amp;quot;zem_slink freebase/en/regular_expression&amp;quot; title=&amp;quot;Regular expression&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/Regular_expression&amp;quot;&amp;gt;regex&lt;/a&gt;&amp;gt;/;#&lt;/tt&gt; This &amp;lt;a class=&amp;quot;zem_slink freebase/en/command_line_interface&amp;quot; title=&amp;quot;Command-line interface&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/Command-line_interface&amp;quot;&amp;gt;command line&lt;/a&gt; will display the output of , from the first line of output, until the first time it sees a &amp;lt;a class=&amp;quot;zem_slink freebase/en/pattern_matching&amp;quot; title=&amp;quot;Pattern matching&amp;quot; rel=&amp;quot;wikipedia&amp;quot; href=&amp;quot;http://en.wikipedia.org/wiki/Pattern_matching&amp;quot;&amp;gt;pattern matching&lt;/a&gt; .&lt;/p&gt;</description>
    </item>
    
    <item>
      <title>Display a block of text with delineated by a start pattern and an end  pattern</title>
      <link>/2009/12/18/display-a-block-of-text-with-delineated-by-a-start-pattern-and-an-end-pattern/</link>
      <pubDate>Fri, 18 Dec 2009 07:43:41 +0000</pubDate>
      
      <guid>/2009/12/18/display-a-block-of-text-with-delineated-by-a-start-pattern-and-an-end-pattern/</guid>
      <description>&lt;!--[ad#ad-2]--&gt;
&lt;p&gt;Taken idea from commandlinefu.com&lt;/p&gt;
&lt;p&gt;The command will display a segment from the file from the start pattern to the end pattern.&lt;/p&gt;
&lt;p&gt;function viewsegment() { tail -n +`fgrep -n -m 1 &amp;ldquo;$1&amp;rdquo; $3 | head -`fgrep -n -m 1 &amp;ldquo;$2&amp;rdquo; $3 }&lt;br&gt;
Display a block of text with delineated by a start pattern and an end pattern&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>
