<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>awk &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/awk/</link>
	<description>Feed of posts on WordPress.com tagged "awk"</description>
	<pubDate>Mon, 30 Nov 2009 05:00:06 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Underwriting Syndicate Bonanza Continues (FTNT, AWK, BZ, LFT, SII) ]]></title>
<link>http://247wallst.com/2009/11/18/underwriting-syndicate-bonanza-continues-ftnt-awk-bz-lft-sii/</link>
<pubDate>Wed, 18 Nov 2009 15:01:34 +0000</pubDate>
<dc:creator>247wallst</dc:creator>
<guid>http://247wallst.com/2009/11/18/underwriting-syndicate-bonanza-continues-ftnt-awk-bz-lft-sii/</guid>
<description><![CDATA[This morning we have a syndicate bonanza with a very solid IPO pricing and many secondary offerings ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="alignleft size-medium wp-image-53885" title="Money Image" src="http://247wallst.wordpress.com/files/2009/11/money-image6.jpg?w=200" alt="" width="142" height="113" />This morning we have a syndicate bonanza with a very solid IPO pricing and many secondary offerings getting priced.  Fortinet, Inc. (NASDAQ: FTNT) priced 12.5 million shares in IPO at $12.50, above the $9.00 to $11.00 range.   There are also many secondary offerings:  American Water Works (NYSE: AWK) 37.35 million shares priced at $21.63; Boise Inc. (NYSE: BZ) 17 million shares priced at $4.85; Longtop Financial Technologies Limited (NYSE: LFT) 3.7 million shares priced at $31.25; Smith International Inc. (NYSE: SII) priced 28 million shares priced at $26.50.</p>
<p>We have detailed information on the size, use of funds, underwriters, and performance on each below.<br />
<!--more--><br />
At Fortinet (NASDAQ: FTNT) and the priced 12.5 million shares in IPO at $12.50, the deal breakdown is as follows for the $156 million offering: 5,781,683 shares are being sold by the company and 6,718,317 shares are being offering by selling stockholders. Morgan Stanley, J.P. Morgan, and Deutsche Bank are joint book-runners; Robert W. Baird, RBC Capital Markets, ThinkEquity, and JMP Securities, and Signal Hill Capital Group LLC are co-managers. In addition, Fortinet has granted the underwriters a 30-day option to purchase up to an additional 1,875,000 shares of common stock to cover over-allotments.  Fortinet is in the field of network security and unified threat management solutions, and it priced above the $9 to $11 indicated range.</p>
<p>American Water Works Company, Inc. (NYSE: AWK), the largest water utility in the U.S., priced a 37.35 million shares at $21.63 per share after a closing bell price of $21.63 yesterday for a sale of close to $800 million.  This stake is entirely from RWE AG, the former parent and majority/largest holder, so none of the $784 million in gross proceeds go to American Water itself.  BofA Merrill Lynch, Credit Suisse, and Morgan Stanley are joint book-runners.  Shares are up 0.3% at $21.71 after a $21.63 close yesterday.</p>
<p>Boise Inc. (NYSE: BZ) 17 million shares priced at $4.85, and all shares here are also being sold by shareholders and insiders in the $82+ million raise.  Goldman Sachs was the sole book-runner.  Boise Cascade Holdings, L.L.C. (and trusts affiliated with Jason Weiss) will now &#8216;only&#8217; hold about 25% of Boise&#8217;s common stock after the offering.  Shares are down 3.3% at $4.92 after a $5.09 close yesterday.</p>
<p>Longtop Financial Technologies Limited (NYSE: LFT) is actually trading way up this morning after it priced 3.7 million shares (ADS&#8217;s) at $31.25 per share, for more than $115 million raised.  Longtop is into software development and solutions which target the financial services industry in China.  The use of the net proceeds of the offering are earmarked for potential acquisitions and for general corporate purposes.  Deutsche Bank and Morgan Stanley were the joint book-runners.</p>
<p>Smith International Inc. (NYSE: SII) priced 28 million shares priced at $26.50 in a $730 million approximate raise.  Oddly enough, Citigroup just raised the rating on Smith International.  The net proceeds from the offering will be used for debt repayment, general corporate purposes, and funding of potential acquisitions or investments.  J.P. Morgan Securities Inc. is the book-running manager for the deal.  Shares are actually up 4% at $27.97.</p>
<p>We are seeing a whole new slate of S-3 secondary filings and still seeing plenty of S-1 IPO filings at the SEC each day.  If the market holds up, there will be many more days where the stock market has to absorb the $1.86 billion absorbed by the market this morning in new shares on the market.</p>
<p>You can <a href="http://247wallst.com/page/free-newsletter/" target="_blank">join our open email distribution list</a> to hear more news on IPOs, secondary offerings, key analyst calls, top day trader alerts, mergers and acquisitions, Buffett and other investment gurus, private equity, and more.</p>
<p>JON C. OGG<br />
November 18, 2009</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[UNIX redirect,pipes &amp; reconfigurable data processing]]></title>
<link>http://billbrouwer.wordpress.com/2009/11/12/unix-redirectpipes-reconfigurable-data-processing/</link>
<pubDate>Thu, 12 Nov 2009 18:39:56 +0000</pubDate>
<dc:creator>bbrouwer</dc:creator>
<guid>http://billbrouwer.wordpress.com/2009/11/12/unix-redirectpipes-reconfigurable-data-processing/</guid>
<description><![CDATA[In various sciences one is often invested in processing voluminous data which follows a given format]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In various sciences one is often invested in processing voluminous data which follows a given format, with many examples following (hopefully) the same format. A typical data file might have a line of environment variables, followed by raw data, which repeats in columns and/or rows eg.,</p>
<p>4,23,45,56,78<br />
12,23,45,56,67,78,89,87,&#8230;,72<br />
32,34,23,21,23,56,43,23,&#8230;,34<br />
34,54,32,45,89,76,54,98,&#8230;,58<br />
67,67,88,32,34,21,22,97,&#8230;,51</p>
<p>A typical section of C code which would use this might look like:</p>
<p style="font-family:courier new;font-size:12px;">float config[8];<br />
scanf(&#8220;%f,%f,%f,%f,%f&#8221;,&#38;config[1],&#38;config[2],&#38;config[3],<br />
&#38;config[4],&#38;config[5]);</p>
<p style="font-family:courier new;font-size:12px;">printf(&#8220;%f,%f,%f,%f,%f\n&#8221;,config[1],config[2],config[3],<br />
config[4],config[5]);</p>
<p style="font-family:courier new;font-size:12px;">int RECORDS = (int) config[1];<br />
int i;<br />
if ( RECORDS &#60; 100){<br />
int SIZE = sizeof(float)*RECORDS;</p>
<p style="font-family:courier new;font-size:12px;">float *deltaCSMean = malloc(SIZE);<br />
float *deltaCSSigma = malloc(SIZE);<br />
float *CQMean = malloc(SIZE);<br />
float *CQSigma = malloc(SIZE);<br />
float *etaMean = malloc(SIZE);<br />
float *etaSigma = malloc(SIZE);<br />
float *brdF2 = malloc(SIZE);<br />
float *brdF1 = malloc(SIZE);<br />
float *amplitude = malloc(SIZE);</p>
<p style="font-family:courier new;font-size:12px;">for (i=0; i&#60; RECORDS; i++){<br />
scanf(&#8220;%f,%f,%f,%f,%f,%f,%f,%f,%f&#8221;,&#38;deltaCSMean[i],<br />
&#38;deltaCSSigma[i],&#38;CQMean[i],&#38;CQSigma[i],<br />
&#38;etaMean[i],&#38;etaSigma[i],<br />
&#38;brdF2[i],&#38;brdF1[i],&#38;amplitude[i]);<br />
printf(&#8220;%f,%f,%f,%f,%f,%f,%f,%f,%f\n&#8221;,deltaCSMean[i],<br />
deltaCSSigma[i],CQMean[i],CQSigma[i],<br />
etaMean[i],etaSigma[i],brdF2[i],brdF1[i],amplitude[i]);<br />
}<br />
}</p>
<p>Using redirect a simple invocation of executable foo using input foo1.txt and output foo2.txt would of course be:</p>
<p style="font-family:courier new;font-size:12px;">./foo &#60; foo1.txt &#62; foo2.txt</p>
<p>which is fine until one needs different data from the file. Supposing in this example data repeats along columns, then one can use awk and a pipe to reshape the data input, removing the need to edit and recompile the C source for different data subsets:</p>
<p style="font-family:courier new;font-size:12px;">
gawk &#8216;BEGIN{FS=&#8221;,&#8221;; print &#8220;4,12,23,44,56&#8243;; getline;} {for(i=lowBnd;i&#60;upBnd;i++){printf(&#8220;%f,&#8221;,$i) }; printf(&#8220;%f\n&#8221;,$upBnd) }&#8217; foo1.txt &#124; ./foo &#62; foo2.txt</p>
<p>where lowBnd and upBnd correspond to the data column limits in the input file. Note that the environment variables are written during the BEGIN block, allowing the specification of (for instance) a different job for the new data set.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Find all lines followed by lines containing xyz]]></title>
<link>http://awkology.wordpress.com/2009/11/10/find-all-lines-followed-by-lines-containing-xyz/</link>
<pubDate>Tue, 10 Nov 2009 12:24:45 +0000</pubDate>
<dc:creator>awkology</dc:creator>
<guid>http://awkology.wordpress.com/2009/11/10/find-all-lines-followed-by-lines-containing-xyz/</guid>
<description><![CDATA[The following script prints all lines of a text file that are followed by a line containing the regu]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The following script prints all lines of a text file that are followed by a line containing the regular expression xyz.</p>
<pre style="font-family:Courier;color:blue;">
awk '{line[NR]=$0;if($0~/xyz/){print line[NR-1]}}' input.file
</pre>
<p>Enjoy.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk] Output formatting]]></title>
<link>http://nixtricks.wordpress.com/2009/11/06/awk-output-formatting/</link>
<pubDate>Fri, 06 Nov 2009 22:18:42 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/11/06/awk-output-formatting/</guid>
<description><![CDATA[If you use print in awk you&#8217;ll lose the formatting of the input file &#8212; most of the times]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>If you use print in awk you&#8217;ll lose the formatting of the input file &#8212; most of the times that may be OK, but not always. The solution is simple &#8212; replace print by printf. Here&#8217;s an example with strings in the input fields:</p>
<div style="border:1px dotted black;padding:1em;"><code>$ awk '{printf "%-20s%-20s%-20s\n", $1, $2, $3}' yourfile.dat</code></div>
<p><span style="color:#ffffff;">.</span></p>
<ul>
<blockquote>
<li>&#8220;%&#8230;s&#8221; means a character string.</li>
<li>20 means a length of 20 characters.</li>
<li>awk defaults to right-alignment (presumably for columns of figures) so you need -20 for left-alignment.</li>
</blockquote>
</ul>
<p><strong>Credit:</strong> <a href="http://www.computing.net/answers/unix/align-fields-in-columns/5637.html" target="_blank">here</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to delete the remaining configuration files after issuing apt-get remove ?]]></title>
<link>http://linuxindetails.wordpress.com/2009/11/05/how-to-delete-the-remaining-configuration-files-after-issuing-apt-get-remove/</link>
<pubDate>Thu, 05 Nov 2009 00:12:06 +0000</pubDate>
<dc:creator>linuxindetails</dc:creator>
<guid>http://linuxindetails.wordpress.com/2009/11/05/how-to-delete-the-remaining-configuration-files-after-issuing-apt-get-remove/</guid>
<description><![CDATA[After issuing a command like apt-get (remove|purge), some configuration files remain whereas the pac]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>After issuing a command like <b>apt-get (remove&#124;purge)</b>, some configuration files remain whereas the packages to whom they belong have just been removed.<br />The following command will help you keeping up to date all the useful configuration files :</p>
<p><b>dpkg &#8211;purge `dpkg &#8211;get-selections&#124;awk &#8216;/deinstall/ {print $1}&#8217;`</b></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=782882f7-6a1d-8d4d-b2d0-7299f2069547" /></div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk] Command line calculator using awk]]></title>
<link>http://nixtricks.wordpress.com/2009/11/03/awk-command-line-calculator-using-awk/</link>
<pubDate>Wed, 04 Nov 2009 00:07:15 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/11/03/awk-command-line-calculator-using-awk/</guid>
<description><![CDATA[This is an update on our bash command line calculator posted a few days ago &#8212; except for the f]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>This is an update on our <a title="Bash command line calculator" href="http://nixtricks.wordpress.com/2009/10/06/bash-command-line-calculator/" target="_self">bash command line calculator</a> posted a few days ago &#8212; except for the fact that this time we&#8217;ll use <code>awk</code> to do the calculation instead of <code>bc</code>. As I mentioned in <a href="http://nixtricks.wordpress.com/2009/10/06/bash-command-line-calculator/" target="_blank">that</a> post, you may use python or ruby (irb) to do the same thing, but these tricks may be useful if you don&#8217;t ruby or python installed (bc and awk, in general, come by default in any Unix or GNU/Linux distro).</p>
<p>First, create (or rewrite if you used our last <a title="Bash command line calculator" href="http://nixtricks.wordpress.com/2009/10/06/bash-command-line-calculator/" target="_self">trick</a>) function &#8220;<code>?</code>&#8221;  as follows and put it in your <code>~/.bashrc</code> file:</p>
<div style="border:1px dotted black;padding:1em;"><code>? () { awk "BEGIN{ print $* }" ;}</code></div>
<p>and make sure to reload your <code>~/.bashrc</code><code> file (do the similar thing if you're using any other shell). [<strong>NOTE:</strong> ZSH does not like ``?'' as a function, so you might consider replacing it with something reasonable, e.g., ``compute'']<br />
</code></p>
<p>Now, if you want to calculate an expression, do it, for example, as</p>
<div style="border:1px dotted black;padding:1em;"><code>$ ? "2*3+4.0*(9.9+8.1)"</code></div>
<p>and don&#8217;t forget the quotes.</p>
<p><span style="color:#ffffff;">.</span></p>
<p>The advantage of this over <a href="http://nixtricks.wordpress.com/2009/10/06/bash-command-line-calculator/" target="_blank">bc</a> is that you can use more arithmetic and trigonometric functions (<a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?awk" target="_blank">link</a>):</p>
<blockquote>
<pre>              atan2(y,x)     Arctan of y/x between -pi and pi.

	      cos(x)	     Cosine function, x in radians.

	      exp(x)	     Exponential function.

	      int(x)	     Returns x truncated towards zero.

	      log(x)	     Natural logarithm.

	      rand()	     Returns a random number between zero and one.

	      sin(x)	     Sine function, x in radians.

	      sqrt(x)	     Returns square root of x.</pre>
</blockquote>
<p><span style="color:#ffffff;">.</span><br />
You may include variables as well in the function definition itself:</p>
<div style="border:1px dotted black;padding:1em;"><code>? () { awk "BEGIN{ pi = 4.0*atan2(1.0,1.0); degree = pi/180.0; print $* }" ;}</code></div>
<p>where we have defined the variable pi and degree (such that tan(pi/4.0) = 1.0 and pi radians is equivalent to 180 degrees) to be used later, e.g.</p>
<div style="border:1px dotted black;padding:1em;"><code>$ ? "cos(pi)"<br />
$ ? "cos(90*degree)"</code></div>
<p>and I&#8217;m sure that you&#8217;ll get -1 and 0 (within the machine precision), respectively, as the answer!</p>
<p>(You may find some more interesting calculator related tricks posted in this blog scattered in different <a href="http://nixtricks.wordpress.com/tag/calculator/" target="_blank">pages</a>)</p>
<p><strong>Credit:</strong> <a href="http://unixhelp.ed.ac.uk/CGI/man-cgi?awk" target="_blank">here</a> and <a href="http://www.commandlinefu.com/commands/view/3871/command-line-calculator" target="_blank">here</a> (via <a href="http://lifehacker.com/5396183/create-an-awesome-command-line-calculator" target="_blank">LifeHacker</a>).</p>
<p><strong>UPDATE:</strong> I just realized that I can use the calc package (besides bc, awk, python and irb) to do the command line math wizardry more efficiently (and let&#8217;s take that as the end to this command line calculator <a href="http://nixtricks.wordpress.com/tag/calculator/" target="_blank">series</a>!). It has a larger set of <a href="http://www.isthe.com/chongo/tech/comp/calc/calc-builtin.html" target="_blank">built-in </a>functions. You may grab the source code from the maintainer&#8217;s <a href="http://www.isthe.com/chongo/tech/comp/calc/" target="_blank">website</a> and follow my <a href="http://nixtricks.wordpress.com/2009/10/31/linux-how-to-install-a-package-from-the-source-code/" target="_blank">instructions</a> to install it on your system [although binaries are also readily available, e.g. <a href="http://packages.ubunut.com/karmic/math/apcalc">apcalc</a> package for Ubuntu 9.10 (Karmic Koala)].</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Awk scripts for reading and editing Ubuntu /etc/network/interfaces file (Part 2/2)]]></title>
<link>http://joekuan.wordpress.com/2009/11/01/awk-scripts-for-reading-and-editing-ubuntu-etcnetworkinterfaces-file-part-22/</link>
<pubDate>Sun, 01 Nov 2009 00:01:48 +0000</pubDate>
<dc:creator>Joe Kuan</dc:creator>
<guid>http://joekuan.wordpress.com/2009/11/01/awk-scripts-for-reading-and-editing-ubuntu-etcnetworkinterfaces-file-part-22/</guid>
<description><![CDATA[For modifying the /etc/network/interfaces file, I use another script and it is slightly more complic]]></description>
<content:encoded><![CDATA[For modifying the /etc/network/interfaces file, I use another script and it is slightly more complic]]></content:encoded>
</item>
<item>
<title><![CDATA[Awk scripts for reading and editing Ubuntu /etc/network/interfaces file (Part 1/2)]]></title>
<link>http://joekuan.wordpress.com/2009/11/01/awk-scripts-for-reading-and-editing-ubuntu-etcnetworkinterfaces-file-part-12/</link>
<pubDate>Sun, 01 Nov 2009 00:00:52 +0000</pubDate>
<dc:creator>Joe Kuan</dc:creator>
<guid>http://joekuan.wordpress.com/2009/11/01/awk-scripts-for-reading-and-editing-ubuntu-etcnetworkinterfaces-file-part-12/</guid>
<description><![CDATA[It is pretty straightforward to setup permanent network configuration on Ubuntu 8.04. All you need i]]></description>
<content:encoded><![CDATA[It is pretty straightforward to setup permanent network configuration on Ubuntu 8.04. All you need i]]></content:encoded>
</item>
<item>
<title><![CDATA[pretty column (field) printing with awk]]></title>
<link>http://brianin3d.wordpress.com/2009/10/27/pretty-column-field-printing-with-awk/</link>
<pubDate>Tue, 27 Oct 2009 18:35:09 +0000</pubDate>
<dc:creator>brianin3d</dc:creator>
<guid>http://brianin3d.wordpress.com/2009/10/27/pretty-column-field-printing-with-awk/</guid>
<description><![CDATA[You know what you have to do&#8230; you have to collect all the strings for every field, keep the ma]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>You know what you have to do&#8230; you have to collect all the strings for every field, keep the max length for each column, then at the end spit them back out again.</p>
<p>But&#8230; you need to store each field for each row and awk only supports 1 dimensional arrays&#8230; suck it up and say the script only supports up to a max of 255 fields:</p>
<pre>
BEGIN {
	row = 0
	max_fields = 0;
	super_max = 255;
} {
	for ( i = 1 ; i &#60;= NF ; i++ ) {
		idx = row + super_max * i;
		len = length( $i );
		data[ idx ] = $i;
		if ( len &#62; max[ i ] ) {
			max[ i ] = len;
		}
	}
	if ( NF &#62; max_fields ) {
		max_fields= NF;
	}
	row++;
} END {
	for ( r = 0 ; r &#60; row ; r++ ) {
		for ( i = 1 ; i &#60;= max_fields ; i++ ) {
			idx = r + super_max * i;
			fmt = "%-" max[ i ]  "s ";
			printf( fmt , data[ idx ], max[ i ]  );
		}
		printf( "\n" );
	}
}
</pre>
<p><a href="http://brianin3d.googlepages.com/columnbo.awk">columnbo.awk</a></p>
<p>Here is some prettified output:</p>
<pre>
this.logger            = logger;
this.dataSourceFactory = dataSourceFactory;
this.wsdlUrl           = wsdlUrl;
this.wsdlKey           = wsdlKey;
this.documentDAO       = documentDAO;
</pre>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Shrouding CSharp and Java Source Code with AWK]]></title>
<link>http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/</link>
<pubDate>Sun, 25 Oct 2009 22:32:11 +0000</pubDate>
<dc:creator>Jim Lawless</dc:creator>
<guid>http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/</guid>
<description><![CDATA[I enjoy tinkering with both Java and C# and publish a lot of my source on this blog under a very lib]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I enjoy tinkering with both Java and C# and publish a lot of my source on this blog under a very liberal open-source license.</p>
<p>I have wondered, however, what I would do if I had to protect a commercial program written in either of the two. The obvious choice would be to purchase a professional obfuscation program that defeats most decompilers.  Fair enough.  Most of these work on the compiled intermediate code.</p>
<p>What, however, if I just wanted to put some mild protection into the compiled product?  The mild protection I refer to would still allow the code to be decompiled back to source form, but the person decompiling would have to work hard to make use of the bulk of the code.</p>
<p>My solution was to try a simple <em>shrouding</em> utility.</p>
<p>Shrouding ( also referred to as <em>fogging</em> ) is a kind of source-level obfuscation that was somewhat popular years ago for C programs sold in source form.  The programs would generally compile but would be unreadable enough that they would discourage someone from using portions of unlicensed code in other programs.</p>
<p>A lot of these source-level shroud utilities are language-aware and determine what variables, functions, methods, and classes are locally-scoped.  The shroud utility then replaces these with generated identifiers.</p>
<p>Most shrouding utilities go a step further and obfuscate literal strings as well as rewriting flow-control constructs.</p>
<p>All I had intended to do was to change the locally-scoped identifier-names to something that my script generates.</p>
<p>My proof-of-concept is an AWK script called <strong>foggy.awk</strong>.  foggy.awk replaces any identifier it finds beginning with two underscore characters with a new identifier containing the prefix &#8220;i_&#8221; and a sequentially generated number.</p>
<p>This means that in my code, I have to observe a coding convention.  I will have to prefix the name of any identifier that should be shrouded with two underscores.</p>
<p>First, here&#8217;s the shrouding script:</p>
<p><strong>foggy.awk</strong></p>
<pre class="brush: cpp;">
# Foggy.awk
# A source-code shrouding utility.
# Replace any &#34;identifier&#34; beginning with __ with a sequentially-
# numbered new identifier
#
# License: MIT / X11
# Copyright (c) 2009 by James K. Lawless
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the &#34;Software&#34;), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
BEGIN {
   legal=&#34;abcdefghijklmnopqrstuvwxyz&#34;;
   legal=legal &#34;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#34;;
   legal=legal &#34;_0123456789&#34; ;
   id_counter=0;
   id_list[&#34;__&#34;]=&#34;__&#34;;
}
{
   state=0;
   s=&#34;&#34;;
   for(i=1;i&#60;=length($0);i++) {
      c=substr($0,i,1);
      if(state==0) {
         if(c==&#34;_&#34;) {
            state=1;
         }
         else {
            s=s c;
         }
      }
      else {
         if(state==1) {
            if(c==&#34;_&#34;) {
               state=2;
               id=&#34;__&#34;;
            }
            else {
               s=s &#34;_&#34; c;
               state=0;
            }
         }
         else {
            # state == 2
            if(index(legal,c)&#60;1) {
               if(id_list[id]==&#34;&#34;) {
                  tmp_id=&#34;i_&#34; id_counter;
                  id_counter++;
                  id_list[id]=tmp_id;
               }
               s=s id_list[id];
                  # decrement the index to forget the current
                  # character we're looking at
               i--;
               state=0;
            }
            else {
               id=id c;
            }
         }
      }
   }
   if(state==0) {
      printf(&#34;%s\n&#34;,s);
   }
   else {
      if(state==1) {
         printf(&#34;%s_\n&#34;,s);
      }
      else {
         if(state==2) {
            if(id_list[id]==&#34;&#34;) {
               tmp_id=&#34;i_&#34; id_counter;
               id_counter++;
               id_list[id]=tmp_id;
            }
            printf(&#34;%s%s\n&#34;,s,id_list[id]);
         }
      }
   }
}
</pre>
<p>As a side note, I have compiled the above script with the Thompson Automation AWK (TAWK) compiler for Windows into the exe <strong>foggy.exe</strong> available in the foggy.zip file referenced at the end of this post.</p>
<p>Unfortunately, TAWK is no longer commercially available.  I reviewed this compiler years ago in Dr. Dobbs Journal.  ( See <em>Examining the TAWK Compiler, DDJ May &#8216;97</em> here: <a href="http://www.ddj.com/architect/184410193">http://www.ddj.com/architect/184410193</a> &#8230;)</p>
<p>I also tested with GNU GAWK for Windows.</p>
<p>I would have preferred to use a regular expression with captured groups, but the AWK tools I have do not support those sorts of regex features.  This likely would have been a smaller Perl script, but I wanted to try it in AWK.  The necessary parser state transitions didn&#8217;t seem to be too deep, so I gave it a go.</p>
<p>To use the above script either type:<br />
<font face="Courier New" color="blue"><br />
gawk -f foggy.awk &#60; inputfle &#62; outputfile<br />
</font></code><br />
...or, if you're using foggy.exe<br />
<font face="Courier New" color="blue"><br />
foggy.awk &#60; inputfle &#62; outputfile<br />
</font></code></p>
<p>Let's first take a look at a Java program that now contains shroud-ready identifiers.  I took the source from MicroHttp1.java from my post here: <a href="http://jimlawless.wordpress.com/2009/08/23/tracing-xslt-with-a-tiny-java-web-server/">http://jimlawless.wordpress.com/2009/08/23/tracing-xslt-with-a-tiny-java-web-server/</a></p>
<pre class="brush: java;">
// MicroHttp1
// A small , specialized web server in Java
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

import java.io.*;
import java.net.*;
import java.util.Date;

public class MicroHttp1Obf {
   public static void main(String[] __args)
      throws IOException {
      ServerSocket __serv;
      Socket __s;
      String __str;
      PrintWriter __pw;
      BufferedReader __br;
      __serv=new ServerSocket(80);
      System.out.println(&#34;Micro HTTP Server v 0.1&#34;);
      System.out.println();
      for(;;){
         __s=__serv.accept();
         __br=new BufferedReader(
            new InputStreamReader(
               __s.getInputStream()));
         for(;;) {
            __str=__br.readLine();
            System.out.println(__str);
            if( ! __br.ready())
               break;
         }
         System.out.println();
         __pw=new PrintWriter(
            __s.getOutputStream(), true);

         __pw.print(&#34;HTTP 200 OK\r\n&#34;);
         __pw.print(&#34;Content-type: text/html\r\n\r\n&#34;);
         __pw.print(&#34;&#60;html&#62;&#60;head /&#62;&#60;body&#62;&#34;);
         __pw.print(&#34;Current date/time &#34; + new Date());
         __pw.print(&#34;&#60;/body&#62;&#60;/html&#62;&#34;);
         __pw.close();
      }
   }
}
</pre>
<p>Note that I had to change the class definition to what I would be targetting for my output filename, since the main Java class and source filename prefix must match.</p>
<p>There are lots of underscores now in this short script.  Here's the shrouded output:</p>
<pre class="brush: java;">
// MicroHttp1
// A small , specialized web server in Java
//
// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

import java.io.*;
import java.net.*;
import java.util.Date;

public class MicroHttp1Obf {
   public static void main(String[] i_0)
      throws IOException {
      ServerSocket i_1;
      Socket i_2;
      String i_3;
      PrintWriter i_4;
      BufferedReader i_5;
      i_1=new ServerSocket(80);
      System.out.println(&#34;Micro HTTP Server v 0.1&#34;);
      System.out.println();
      for(;;){
         i_2=i_1.accept();
         i_5=new BufferedReader(
            new InputStreamReader(
               i_2.getInputStream()));
         for(;;) {
            i_3=i_5.readLine();
            System.out.println(i_3);
            if( ! i_5.ready())
               break;
         }
         System.out.println();
         i_4=new PrintWriter(
            i_2.getOutputStream(), true);

         i_4.print(&#34;HTTP 200 OK\r\n&#34;);
         i_4.print(&#34;Content-type: text/html\r\n\r\n&#34;);
         i_4.print(&#34;&#60;html&#62;&#60;head /&#62;&#60;body&#62;&#34;);
         i_4.print(&#34;Current date/time &#34; + new Date());
         i_4.print(&#34;&#60;/body&#62;&#60;/html&#62;&#34;);
         i_4.close();
      }
   }
}
</pre>
<p>There are really only about five shrouded identifiers in this program.  I suppose someone who really wanted to work at it could perform global search-and-replace operations to change them into something meaningful as they analyze the code.</p>
<p>Let's try something a little larger that has more local identifiers.  For this next test, I took the C# source code from my command-line Twitter client <strong>Twimmando</strong>.  See: <a href="http://jimlawless.wordpress.com/2009/05/24/twimmando-a-command-line-twitter-client/">http://jimlawless.wordpress.com/2009/05/24/twimmando-a-command-line-twitter-client/</a></p>
<p>Here's the shroud-ready source:</p>
<pre class="brush: cpp;">
// Twimmando - a command-line Twitter client

// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Net;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;

namespace Twimmando
{

   public enum __RequestMethod
   {
      __Get,
      __Post,
      __Head
   }
   class __Config
   {
      public __RequestMethod __Method;
      public string __Uri;
      public string __UserName;
      public string __Password;
      public string __PostData;
   }

   class __Twimmando
   {
      public static string __Version = &#34;Twimmando v1.01 (obfuscated)&#34;;
      public static void Main(string[] __args)
      {
         __Config __config;
         try
         {
            __config=__processCommandLine(__args);
            if(__config.__Uri==null)
               Environment.Exit(1);
            __doHttpRequest(__config);
         }
         catch(Exception e)
         {
            Console.Error.WriteLine(e.ToString());
            Environment.Exit(1);
         }
         Environment.Exit(0);
      }

      public static __Config __processCommandLine(string[] __args)
      {
         int __i;
         __Config __config=new __Config();
         __config.__PostData=&#34;&#34;;
         __config.__Method=__RequestMethod.__Get;

         for(__i=0;__i&#60;__args.Length;__i++) {
            if(string.Compare(__args[__i],&#34;-head&#34;,true)==0) {
               __config.__Method=__RequestMethod.__Head;
            }
            else
            if(string.Compare(__args[__i],&#34;-post&#34;,true)==0) {
               __config.__Method=__RequestMethod.__Post;
            }
            else
            if(string.Compare(__args[__i],&#34;-uri&#34;,true)==0) {
               __config.__Uri=__args[++__i];
            }
            else
            if(string.Compare(__args[__i],&#34;-u&#34;,true)==0) {
               __config.__UserName=__args[++__i];
            }
            else
            if(string.Compare(__args[__i],&#34;-p&#34;,true)==0) {
               __config.__Password=__args[++__i];
            }
            else
            if(string.Compare(__args[__i],&#34;-f&#34;,true)==0) {
               if(__config.__PostData.Length&#62;0) {
                  __config.__PostData+=&#34;&#38;&#34;;
               }
               __config.__PostData+=__args[__i+1]+&#34;=&#34;+HttpUtility.UrlEncode(__args[__i+2]);
               __i+=2;
            }
         }
         if(__config.__Uri==null) {
            Console.WriteLine(__Twimmando.__Version + &#34;\nby Jim Lawless (@lawlessGuy)&#34;);
            Console.WriteLine(&#34;Usage:\n\ttwimmando [options]\nWhere options are:&#34;);
            Console.WriteLine(&#34;   -uri resourceURI   ; such as /statuses/public_timeline.xml&#34;);
            Console.WriteLine(&#34;   -u username        ; Twitter password&#34;);
            Console.WriteLine(&#34;   -p password        ; Twitter user name&#34;);
            Console.WriteLine(&#34;   -head              ; send HTTP HEAD request, default is GET&#34;);
            Console.WriteLine(&#34;   -post              ; send HTTP POST request, default is GET&#34;);
            Console.WriteLine(&#34;   -f name value      ; add POST data name/value pair to request&#34;);
         }
         return __config;
      }

      public static void __doHttpRequest(__Config __config)
      {

         HttpWebRequest __webRequest;
			HttpWebResponse __webResponse;
         Uri __uri=new Uri(&#34;http://twitter.com&#34; + __config.__Uri);
			__webRequest = (HttpWebRequest)HttpWebRequest.Create(__uri);
         if(__config.__Password!=null) {
            __webRequest.Credentials = new NetworkCredential(__config.__UserName, __config.__Password);
         }

	 __webRequest.UserAgent = __Twimmando.__Version;
         if(__config.__Method==__RequestMethod.__Post) {
            __webRequest.Method = &#34;POST&#34;;
               // remove Expect header
            __webRequest.ServicePoint.Expect100Continue = false;
            __webRequest.ContentType=&#34;application/x-www-form-urlencoded&#34;;
            __webRequest.ContentLength = __config.__PostData.Length;
            StreamWriter __sOut=new StreamWriter(__webRequest.GetRequestStream(),System.Text.Encoding.ASCII);
            __sOut.Write(__config.__PostData);
            __sOut.Close();
         }
         else
         if(__config.__Method==__RequestMethod.__Head) {
            __webRequest.Method=&#34;HEAD&#34;;
         }
	 __webResponse = (HttpWebResponse)__webRequest.GetResponse();
         if(__config.__Method==__RequestMethod.__Head) {
            Console.WriteLine(__webResponse.Headers.ToString());
         }
         else {
            Stream __stream = __webResponse.GetResponseStream();
            StreamReader __streamReader =
               new StreamReader(__stream, Encoding.ASCII);
            Console.WriteLine(__streamReader.ReadToEnd());
         }
         __webResponse.Close();
      }
   }
}
</pre>
<p>Here's the encoded result:</p>
<pre class="brush: plain;">
// Twimmando - a command-line Twitter client

// License: MIT / X11
// Copyright (c) 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the &#34;Software&#34;), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED &#34;AS IS&#34;, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

using System;
using System.Net;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web;

namespace Twimmando
{

   public enum i_0
   {
      i_1,
      i_2,
      i_3
   }
   class i_4
   {
      public i_0 i_5;
      public string i_6;
      public string i_7;
      public string i_8;
      public string i_9;
   }

   class i_10
   {
      public static string i_11 = &#34;Twimmando v1.01 (obfuscated)&#34;;
      public static void Main(string[] i_12)
      {
         i_4 i_13;
         try
         {
            i_13=i_14(i_12);
            if(i_13.i_6==null)
               Environment.Exit(1);
            i_15(i_13);
         }
         catch(Exception e)
         {
            Console.Error.WriteLine(e.ToString());
            Environment.Exit(1);
         }
         Environment.Exit(0);
      }

      public static i_4 i_14(string[] i_12)
      {
         int i_16;
         i_4 i_13=new i_4();
         i_13.i_9=&#34;&#34;;
         i_13.i_5=i_0.i_1;

         for(i_16=0;i_16&#60;i_12.Length;i_16++) {
            if(string.Compare(i_12[i_16],&#34;-head&#34;,true)==0) {
               i_13.i_5=i_0.i_3;
            }
            else
            if(string.Compare(i_12[i_16],&#34;-post&#34;,true)==0) {
               i_13.i_5=i_0.i_2;
            }
            else
            if(string.Compare(i_12[i_16],&#34;-uri&#34;,true)==0) {
               i_13.i_6=i_12[++i_16];
            }
            else
            if(string.Compare(i_12[i_16],&#34;-u&#34;,true)==0) {
               i_13.i_7=i_12[++i_16];
            }
            else
            if(string.Compare(i_12[i_16],&#34;-p&#34;,true)==0) {
               i_13.i_8=i_12[++i_16];
            }
            else
            if(string.Compare(i_12[i_16],&#34;-f&#34;,true)==0) {
               if(i_13.i_9.Length&#62;0) {
                  i_13.i_9+=&#34;&#38;&#34;;
               }
               i_13.i_9+=i_12[i_16+1]+&#34;=&#34;+HttpUtility.UrlEncode(i_12[i_16+2]);
               i_16+=2;
            }
         }
         if(i_13.i_6==null) {
            Console.WriteLine(i_10.i_11 + &#34;\nby Jim Lawless (@lawlessGuy)&#34;);
            Console.WriteLine(&#34;Usage:\n\ttwimmando [options]\nWhere options are:&#34;);
            Console.WriteLine(&#34;   -uri resourceURI   ; such as /statuses/public_timeline.xml&#34;);
            Console.WriteLine(&#34;   -u username        ; Twitter password&#34;);
            Console.WriteLine(&#34;   -p password        ; Twitter user name&#34;);
            Console.WriteLine(&#34;   -head              ; send HTTP HEAD request, default is GET&#34;);
            Console.WriteLine(&#34;   -post              ; send HTTP POST request, default is GET&#34;);
            Console.WriteLine(&#34;   -f name value      ; add POST data name/value pair to request&#34;);
         }
         return i_13;
      }

      public static void i_15(i_4 i_13)
      {

         HttpWebRequest i_17;
			HttpWebResponse i_18;
         Uri i_19=new Uri(&#34;http://twitter.com&#34; + i_13.i_6);
			i_17 = (HttpWebRequest)HttpWebRequest.Create(i_19);
         if(i_13.i_8!=null) {
            i_17.Credentials = new NetworkCredential(i_13.i_7, i_13.i_8);
         }

	 i_17.UserAgent = i_10.i_11;
         if(i_13.i_5==i_0.i_2) {
            i_17.Method = &#34;POST&#34;;
               // remove Expect header
            i_17.ServicePoint.Expect100Continue = false;
            i_17.ContentType=&#34;application/x-www-form-urlencoded&#34;;
            i_17.ContentLength = i_13.i_9.Length;
            StreamWriter i_20=new StreamWriter(i_17.GetRequestStream(),System.Text.Encoding.ASCII);
            i_20.Write(i_13.i_9);
            i_20.Close();
         }
         else
         if(i_13.i_5==i_0.i_3) {
            i_17.Method=&#34;HEAD&#34;;
         }
	 i_18 = (HttpWebResponse)i_17.GetResponse();
         if(i_13.i_5==i_0.i_3) {
            Console.WriteLine(i_18.Headers.ToString());
         }
         else {
            Stream i_21 = i_18.GetResponseStream();
            StreamReader i_22 =
               new StreamReader(i_21, Encoding.ASCII);
            Console.WriteLine(i_22.ReadToEnd());
         }
         i_18.Close();
      }
   }
}
</pre>
<p>This shrouded program was much more difficult for me to read, as I used some local class definitions and used more local variables and methods than I had used in the sample Java program.</p>
<p>My conclusion?</p>
<p>Well, if I <strong>had to</strong> employ this method, I think I could grow into learning to deal with the added noise of the extra underscores in the source.</p>
<p>However, I still think that language-aware shrouding utilities would be much less painful to use.</p>
<p>The source and Windows executable file for foggy.awk can be downloaded in a single archive at:<br />
<a href="http://www.mailsend-online.com/wp/foggy.zip">http://www.mailsend-online.com/wp/foggy.zip</a></p>
<p><a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="del_icio_us" src="http://www.mailsend-online.com/wp/del_icio_us.png" alt="del_icio_us" /></a> <a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">Save to del.icio.us</a><br /><a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="digg" src="http://www.mailsend-online.com/wp/digg.png" alt="digg" /></a> <a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">Digg it</a><br /><a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="reddit" src="http://www.mailsend-online.com/wp/reddit.png" alt="reddit" /></a> <a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/&#38;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">Save to Reddit</a><br /><a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/" target="_blank"><img title="facebook" src="http://www.mailsend-online.com/wp/facebook.png" alt="facebook" /></a> <a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/" target="_blank">Share on Facebook</a><br /><a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/"><img title="twitter" src="http://www.mailsend-online.com/wp/twitter.gif" alt="twitter" /></a> <a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/" target="_blank">Share on Twitter</a><br /><a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank"><img title="aolfav" src="http://www.mailsend-online.com/wp/aolfav.gif" alt="aolfav" /></a> <a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/10/25/shrouding-csharp-and-java-source-code-with-awk/;title=Shrouding+CSharp+and+Java+Source+Code+with+AWK" target="_blank">More bookmarks</a>
<p><img src="http://www.mailsend-online.com/cgi-bin/wphit.pl" /><br />
<em>Unless otherwise noted, all code and text entries are Copyright © 2009 by James K. Lawless</em></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk] Add another column from a second file]]></title>
<link>http://nixtricks.wordpress.com/2009/10/24/awk-add-another-column-from-a-second-fil/</link>
<pubDate>Sat, 24 Oct 2009 18:25:34 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/10/24/awk-add-another-column-from-a-second-fil/</guid>
<description><![CDATA[The problem: I have  two files, file-1 and file-2, each of which has two columns; and I want to add ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>The problem: </strong>I have  two files, file-1 and file-2, each of which has two columns; and I want to add the second column of the second file as the third column in the first file.<br />
Let&#8217;s say the following is the content of file-1:</p>
<blockquote><p>A   1<br />
B   2<br />
C   3</p></blockquote>
<p>and that of file-2:</p>
<blockquote><p>D    4<br />
E    5<br />
F     6</p></blockquote>
<p>and I want to have something like this in file-3</p>
<blockquote><p>A    1    4<br />
B    2    5<br />
C   3    6</p></blockquote>
<p>Of course, the actual data are not as simple as the above!</p>
<p><strong>Solution:</strong></p>
<pre class="brush: bash;">$ awk '{str1=$1; str2=$2; getline &#38;lt; &#34;file-2&#34;; print str1&#34; \t &#34;str2&#34; \t &#34;$2 &#38;gt; &#34;file-3&#34;}' file-1</pre>
<p>I inserted the tab characters (\t) just to make  file-3 look nice (scientists don&#8217;t care about white spaces, do they?)!</p>
<p><strong>Reference: </strong><a href="http://www.computing.net/answers/unix/awk-from-two-files-into-one-file/6194.html" target="_blank">here</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[sum,avg,min,max with awk]]></title>
<link>http://brianin3d.wordpress.com/2009/10/15/sumavgminmax-with-awk/</link>
<pubDate>Thu, 15 Oct 2009 17:09:00 +0000</pubDate>
<dc:creator>brianin3d</dc:creator>
<guid>http://brianin3d.wordpress.com/2009/10/15/sumavgminmax-with-awk/</guid>
<description><![CDATA[awk &#8216;BEGIN{count=0;sum=0;min=0;max=0} {n=$1 ; if (0==count||nmax) max=n; count++; sum+=n;} END]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>awk &#8216;BEGIN{count=0;sum=0;min=0;max=0} {n=$1 ; if (0==count&#124;&#124;nmax) max=n; count++; sum+=n;} END {printf( &#8220;min: %d\nmax: %d\nsum: %d\ncnt: %d\navg: %f\n&#8221;, min,max, sum,count, sum/count );}&#8217;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Stocks That Missed the Rally (ABT, MO, AWK, BKC, ENER, GENZ, KR, ORB, WMT, LEAP, PCS)]]></title>
<link>http://247wallst.com/2009/10/12/stocks-that-missed-the-rally-abt-mo-awk-bkc-ener-genz-kr-orb-wmt-leap-pcs/</link>
<pubDate>Mon, 12 Oct 2009 21:03:59 +0000</pubDate>
<dc:creator>247wallst</dc:creator>
<guid>http://247wallst.com/2009/10/12/stocks-that-missed-the-rally-abt-mo-awk-bkc-ener-genz-kr-orb-wmt-leap-pcs/</guid>
<description><![CDATA[Here we are going into yet another earnings season.  We saw Monday how the market has rallied signif]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Here we are going into yet another earnings season.  We saw Monday how the market has rallied significantly from the March lows and the major indexes are even up in positive territory for the 2009 calendar.  The DJIA is up 51% from its absolute lows of March, and the S&#38;P 500 has rallied more than 61% from its absolute lows in March.  If you look at the December 31, 2008 closing bell levels, the DJIA is now up about 12.75% and the S&#38;P 500 is now up more than 19% year-to-date.</p>
<p>But almost as always, there are still some key very large and/or very active stocks which have not recovered anywhere close to the same amounts with the overall stock markets.  Some of these lagging stocks are Abbott Laboratories (NYSE: ABT), Altria Group Inc. (NYSE: MO), American Water Works Company, Inc. (NYSE: AWK), Burger King Holdings Inc. (NYSE: BKC), Energy Conversion Devices, Inc. (NASDAQ: ENER), Genzyme Corp. (NASDAQ: GENZ), Kroger Co. (NYSE: KR), Orbital Sciences Corp. (NYSE: ORB) and Wal-Mart Stores Inc. (NYSE: WMT).  Two similar situation stocks that are Leap Wireless International Inc. (NASDAQ: LEAP) and MetroPCS Communications Inc. (NYSE: PCS).  We wanted to explore the forward values and relative performance, and the consensus estimates based upon Thomson Reuters data.  Only two of these stocks have market capitalization rates under $1 billion, and almost all are very actively traded and well known in their sectors.<br />
<!--more--><br />
Abbott Laboratories (NYSE: ABT) is on deck to report earnings this week and it was surprising how far it has lagged to some of the large peers.  The good news is that it has started to participate in the rally with a 10% gain over the last month.  Saying it has &#8216;only&#8217; recovered by 21% from its April-May lows shows how well the market sentiment is and how well other stocks have performed.  But shares are only about 10% higher from the early March inflection point lows.  Abbott trades at about 12.2-times normalized 2010 earnings estimates of $4.12 and the stock carries a 3.2% dividend yield.  Guidance was spotty before and obviously the sector has political risks into 2010 and beyond because it is tied to healthcare.</p>
<p>Altria Group Inc. (NYSE: MO) might not be a shock that it has lagged if you believe that smoking is a dead industry in the future.  But the one recognition that has always been the case is that Big Tobacco has always survived.  Things are even good enough that it recently juiced up its dividend and appears to have enough earnings power for plenty of dividend coverage for the future.  It is hard to bash a stock that has risen 28% from the March lows, but this greatly lags the performance of Philip Morris International, Inc. (NYSE: PM), Reynolds American Inc. (NYSE: RAI) and Lorillard, Inc. (NYSE: LO).  The Big-Mo trades at just under 10-times a normalized estimate of $1.85 EPS for 2010 and its dividend yield is almost 7.5% now that it has been hiked.  This only needs to rally about 14% to hit 52-week highs, so this is just representative more of nearly-dead money rather than anything that looks or feels sinister.</p>
<p>American Water Works Company, Inc. (NYSE: AWK) is in that long-discussed great sector of water, but as a utility.  It may just be more shares sold and the risks of more shares being sold, but this one has effectively been dead money ever since it came public (again).  At almost $20.00, shares are up about 23% from the absolute lows. That looks to be well under all of its larger peers here in the U.S.  This stock and sector does have a premium considering the utility status, but analysts are looking for growth from 2009 to 2010.  This one trades at less than 14-times normalized earnings estimates of $1.46 EPS for 2010.  America&#8217;s largest water utility did hike its dividend for August and it now yields about 4.2%.</p>
<p>Burger King Holdings Inc. (NYSE: BKC) is supposed to be in a class of eating-out that wins in recessions via fast food and very casual dining.  It seems like that crazy looking king character in commercials that scared so many kids has also scared investors.  This company has only recovered some 13% from its recent 52-week lows despite only trading at about 12.2-times its Fiscal-2010 (June) earnings estimates.  Its market cap is just under $2.4 billion.  The much larger, and far better-run, McDonald&#8217;s Corp. (NYSE: MCD) has not exactly been a performing beast this year, but its shares are up 25% from lows.  The Big Whopper would also have to rally almost 50% before hitting 52-week highs.  Unfortunately, its dividend yield is only about 1.4%.  For this to start performing again, management is going to have to do a better turnaround plan than what it has managed so far.</p>
<p>Energy Conversion Devices, Inc. (NASDAQ: ENER) is one where the figures are actually a tad better than what is reflected because of the solid gains seen on Monday.  Before Monday, this one was not even 10% above its 52-week lows and shares are still under the inflection point lows in the market during March.  Despite this being one of the old top solar stocks for traders, it has failed miserably to bounce when you consider the bounce of the major solar players.  First Solar, Inc. (NASDAQ: FSLR) is up over 75% and Suntech Power Holdings Co. Ltd. (NYSE: STP) is up almost 200% from its absolute lows over the last year.  Unfortunately this is expected to post a loss for all of its Fiscal 2010 (June) and estimates are $0.28 for its following Fiscal 2011 (June).  There is no dividend and this is likely to trade around how well oil prices do and on its own guidance and not its trading based on how the market does.  This is down from a 52-week high north of $48 and down from a peak of $80 back in the Summer-2008 highs.  No dividends are to be found here.</p>
<p>Genzyme Corp. (NASDAQ: GENZ) did recover from lows in August.  This troubled biotech giant is up about 20% from the absolute lows in August and &#8216;only&#8217; up about 16% from its lowest close of $48.19 in August.  The reason here is simple.  Serious manufacturing issues resulted in contamination issues, and the company is effectively under a red flag warning by the FDA.  But this also trades at a much deeper discount than most of the large biotech stocks.  It would take close to a 50% rally for this to challenge its old 2008 highs.  The question that exists here is not over whether it still has an addressable market, but whether it can get its house entirely back in order before competition comes on in 2010.  Like most biotech companies, it has no dividend.  Earnings estimates are now all over the place, but it trades at roughly 14-times normalized 2010 earnings.  Even if you take a median estimate over an average estimate for 2010, that forward multiple is only around 15-times 2010 earnings.  Of course there are still risks here, but that is why the stock is already down so much on its woes.</p>
<p>Kroger Co. (NYSE: KR) was also up on Monday as an analyst upgraded the stock on valuation.  But the stock is still a laggard compared to rival Safeway (NYSE: SWY).  The company&#8217;s latest earnings report kept it from rallying because it was still experiencing difficult pricing and that has kept its shares from rallying.  We have barely seen a 15% gain since March&#8217;s lows.  Its 2010 ends in January 2011, but it trades at 10.4-times the $2.14 estimate.  This is representative of a mature grocery sector and the discount to Safeway is small but still there:  Safeway is up 24% from its lows and trades at 11-times the comparable forward earnings.  Analysts are still looking for growth and this would have to rally over 30% before its 52-week highs came back into play.</p>
<p>Orbital Sciences Corp. (NYSE: ORB) may seem the riskiest of all these underperforming stocks as its main operations are in small space and rocket systems, as well as GEO satellites for communications and broadcasting and LEO spacecraft that perform remote sensing and scientific research.  But effectively, the company is a pure-play on space operation and exploration, including deep space.  This stock is still down about one-third from a year ago and is &#8216;only&#8217; up 22% from its lows in March.  Earnings estimates have come down over the last quarter but there has not been a significant downgrade worth noting from analysts of late.  With the government purse being tight and with the Obama administration reportedly considering privatizing much space exploration, a wild card exists here.  Loral Space &#38; Communications (NASDAQ: LORL) is considered its top comparable stock, and that one has risen exponentially from its lows.</p>
<p>Wal-Mart Stores Inc. (NYSE: WMT) is supposed to be the winner in the recession, right?  Yet don&#8217;t go looking for it to be the golden child of stock performance.  And its 2.2% dividend yield might not sound like much.  Wal-Mart is under $50.00, and is only about 8% above its 52-week lows.  It would also take &#8216;only&#8217; a 20% gain for Wal-Mart to challenge its 52-week highs.  And year-to-date the stock is down 10%.  It seems that its policy of dropping guidance and its same store sales reporting has not been as rewarding as it would hope.  Now the valuation question for the world&#8217;s largest retailer.  This trades at about 13.7-times a normalized 2010 earnings (actually Jan. 2011) estimate of $3.92.  Wal-Mart is still growing.  It would also seem as though that as long as there is an army of unemployed and as long as the notion of thrift is semi-secular, then this is lagging and cheap. Target Corp. (NYSE: TGT) trades at about 14.5-times 2010 comparable estimates, but Target has also almost doubled from its absolute lows.  Costco Wholesale Corporation (NASDAQ: COST) has rallied 50% from its lows, despite a much higher forward multiple.</p>
<p>Leap Wireless International Inc. (NASDAQ: LEAP) and MetroPCS Communications Inc. (NYSE: PCS) are two very similar companies that have been gross disappointments.  Despite the overall wireless sector being a tough space and despite fairly low performance even from the leaders, these two have been an outright disappointment by every single measurement besides being great performers for short sellers.  As there once was a merger on the table (which was blocked) and as these are both in the no-contract or pre-paid wireless sector, we are only going to mention the performance metrics.</p>
<ul>
<li>Leap Wireless is down close to 40% year to date.  The stock is up about 15% from its 52-week low.</li>
<li>MetroPCS is down over 45% year to date.  The stock is also not even 10% off of its 52-week lows.</li>
</ul>
<p>Leap is now expected to lose money in 2010, and if the $0.69 estimate is right on MetroPCS then it trades at about 12-times 2010 estimates.  Unfortunately, that is 20-times a 2009 estimate for MetroPCS.  We won&#8217;t go as far as to predict a merger here, but a proposed merger this time around could be out of need and not out of greed.</p>
<p>Again, the estimates are based on Thomson Reuters estimates and share performance is based from the weekend when a static snapshot existed equally among all.  Many of these estimates will change throughout this earnings season.  Despite the rally, there are still some very large or very active stocks which have just not participated.</p>
<p>JON C. OGG<br />
OCTOBER 12, 2009</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[X11 Display Variable automatisch setzen...]]></title>
<link>http://sebastiang63.wordpress.com/2009/10/05/x11-display-variable-automatisch-setzen/</link>
<pubDate>Mon, 05 Oct 2009 11:43:38 +0000</pubDate>
<dc:creator>sebastiang63</dc:creator>
<guid>http://sebastiang63.wordpress.com/2009/10/05/x11-display-variable-automatisch-setzen/</guid>
<description><![CDATA[Ja, ich hab mir auch &#8216;nen VServer zugelegt. Warum? Nun, es bietet die Möglichkeit so ganz nebe]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Ja, ich hab mir auch &#8216;nen VServer zugelegt. Warum?<br />
Nun, es bietet die Möglichkeit so ganz nebenbei einen eigenen Teamspeak-Server laufen zu lassen, falls man mal mit jemand quatschen will, beim Entwickeln der nächsten OpenSource, beim Spielen von irgendwas, oder auch einfach mal so. Und wenn man mag, kann man auch noch seine Homepage oder so Zeugs drauf packen. Außerdem ist ein VServer im Grunde nicht teurer als ein weiterer Rechner, der zuhause nur rumsteht, Strom frisst, Lärm produziert und Platz wegnimmt.<br />
Nun zeigt sich aber leider die Problematik, daß das gute Stück im Zusammenspiel mit PuTTY/Xming nicht so ganz gerne X11 Anwendungen auf den heimischen Windows-Rechner bringen mag.<br />
Das grausamste Szenario bleibt, nach jedem Login auf dem Unix-Rechner im Internet, mit der Hand die  $DISPLAY-Umgebungsvariable setzen zu müssen. Das nervt natürlich gewaltig, zumal Umgebungsvariablen, wie $SSH_CLIENT und $SSH_CONNECTION in der Regel bereits richtig gesetzt sind. Leider hat PuTTY jedoch Probleme die aktuell korrekte dynamische IP-Adresse für den eigenen DSL-Zugang richtig zu erkennen und entsprechend auf dem Zielsystem zu setzen.<br />
Pfui, PuTTY! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Nun, es gibt dennoch einfache Lösungen für diese Problemstellung, die uns das manuelle Setzen der $DISPLAY Umgebungsvariable einfach machen. Hier eine recht simple Variante davon, vorausgesetzt, die $SSH_CLIENT Umgebungsvariable ist bereits korrekt gesetzt, was jedoch in der Regel der Fall ist, da diese das Zielsystem evaluiert wird, nicht durch PuTTY selbst.<br />
Zunächst extrahieren wir aus $SSH_CLIENT unsere korrekte aktuelle IP-Adresse mit einem kleinen Programm, welches daraus eine &#8220;DISPLAY=client-ip:0.0&#8243; Zeichenkette formt und diese auf &#8220;stdout&#8221; zurückliefert. <i>Die Verwendung von putenv() oder setenv() zwecks direktem Setzen der Umgebungsvariable hätte an dieser Stelle nicht die gewünschte Wirkung.</i></p>
<p>Der zweite Teil der Lösung ist, unseren generierten $DISPLAY-String in die Umgebung zu schubsen. Das machen wir am besten im &#8220;<strong>.profile</strong>&#8220;, welches beim Login ausgeführt wird.<br />
Für eine bash-Shell, wäre das z.B. eine Zeile wie, &#8220;<strong>export $(./evaldisp)</strong>&#8220;, wobei &#8220;evaldisp&#8221; unser kleines Programm wäre, welches die $DISPLAY-Zeichenkette liefert. Die Zeile &#8220;<strong>export $(./evaldisp)</strong>&#8221; bewirkt, daß zunächst unser kleines Programm &#8220;evaldisp&#8221; ausgeführt wird und die zurückgelieferte Zeichenkette &#8220;DISPLAY=&#8230;&#8221; als Variable für den &#8220;export&#8221; in die Umgebung verwendet wird.</p>
<p>Wenn wir nun nach dem Login in unseren gemieteten Unix-VServer ein X11 Programm aufrufen, müssen wir nicht mehr nachsehen, welche IP Adresse wir aktuell haben und diese mit der Hand setzen, sonder ein simples &#8220;xterm&#8221;, &#8220;emacs&#8221; oder &#8220;xeyes&#8221; reicht nun völlig aus, da die Umgebung bereits das $DISPLAY über unsere kleine Hilfestellung korrekt gesetzt hat.</p>
<p>Und nicht vergessen zuhause Xming laufen zu lassen&#8230; man möchte ja auch die X11-Anwendung auf dem Desktop sehen können <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hier ein C-Beispiel für unser &#8220;evaldisp&#8221; Programm, das wir mit &#8220;<strong>cc evaldisp.c -o evaldisp</strong>&#8221; compilieren können:<br />
<code><br />
/* evaldisp.c */<br />
#include "stdio.h"<br />
#include "stddef.h"<br />
#include "stdlib.h"<br />
#include "string.h"<br />
int main( int argc, char* argv[] )<br />
{<br />
  char buf[512];<br />
  char* pc1 = getenv( "SSH_CLIENT" );<br />
  char* pc2 = strchr( pc1, ' ' ); /* get end of IP address */<br />
  *pc2 = '0'; /* set end of string */<br />
  memset( buf, 0, 512 );<br />
  sprintf( buf, "DISPLAY=%s:0.0", pc1 ); /* create $DISPLAY string */<br />
  *pc2=' '; /* set back to original value*/<br />
  printf( "%s\n", buf ); /* return $DISPLAY via stdout */<br />
  return EXIT_SUCCESS;<br />
}<br />
</code></p>
<p>Alternativ hier noch eine Variante, bei mittels Python, anstelle von C, die IP-Adresse aus der Umgebungsvariable $SSH_CLIENT filtert:<br />
<code><br />
#evaldisp.py<br />
import os<br />
s1 = os.getenv("SSH_CLIENT")<br />
l1 = s1.split(' ')<br />
print "DISPLAY=%(ip)s:0.0" % { 'ip':l1[0] }<br />
</code><br />
Ensprechend lautet der Aufruf in &#8220;<strong>.profile</strong>&#8221; dann, &#8220;<strong>export $(python evaldisp.py)</strong>&#8220;.</p>
<p><strong>~~~Nachtrag:</strong></p>
<p>Und der Vollständigkeit halber, ich wurde darauf hingewiesen, man könne unter Verwendung von <strong>awk</strong> die Problematik auch in einem Einzeiler in <strong>.profile</strong> formulieren. Danke für den Hinweis und hier die entsprechende Zeile:</p>
<p><code>export DISPLAY=$(echo $SSH_CLIENT&#124;awk ‘{print $1 ":0.0"}’)</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk] Standard deviation of a column of numbers in the command line]]></title>
<link>http://nixtricks.wordpress.com/2009/09/27/awk-standard-deviation-of-a-column-of-numbers-in-the-command-line/</link>
<pubDate>Mon, 28 Sep 2009 01:05:06 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/09/27/awk-standard-deviation-of-a-column-of-numbers-in-the-command-line/</guid>
<description><![CDATA[Just picked this up from my favorite site: commandline-fu. $ awk '{delta = $1 - avg; avg += delta / ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Just picked this up from my favorite site: <a href="http://www.commandlinefu.com/commands/view/3442/display-the-standard-deviation-of-a-column-of-numbers-with-awk#comment">commandline-fu</a>.<br />
<code><br />
$ awk '{delta = $1 - avg; avg += delta / NR; mean2 += delta * ($1 - avg); } END { print sqrt(mean2 / NR); }'<br />
</code></p>
<p>Let&#8217;s test it by finding the standard deviation of 1, 2, 3, 4, and 5 whose standard deviation is sqrt(2): in BASH, pipe in the out put of the following (which just echoes out numbers from 1 through 5)  to the above command to find that it is in fact sqrt(2) or 1.42421<br />
<code>$ for n in {1..5}; do echo $n; done<br />
</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk]ファイルをタブ区切りにいして1列目を表示]]></title>
<link>http://siguniang.wordpress.com/2009/09/27/awk%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%bf%e3%83%96%e5%8c%ba%e5%88%87%e3%82%8a%e3%81%ab%e3%81%84%e3%81%97%e3%81%a61%e5%88%97%e7%9b%ae%e3%82%92%e8%a1%a8%e7%a4%ba/</link>
<pubDate>Sun, 27 Sep 2009 05:32:07 +0000</pubDate>
<dc:creator>siguniang</dc:creator>
<guid>http://siguniang.wordpress.com/2009/09/27/awk%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%bf%e3%83%96%e5%8c%ba%e5%88%87%e3%82%8a%e3%81%ab%e3%81%84%e3%81%97%e3%81%a61%e5%88%97%e7%9b%ae%e3%82%92%e8%a1%a8%e7%a4%ba/</guid>
<description><![CDATA[awk 'BEGIN { FS = "\t" } ; { print $1 }'  /path/to/file gawk manual: 3.5.3 Setting FS from the Comma]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><pre style="padding-left:30px;">awk 'BEGIN { FS = "\t" } ; { print $1 }'  /path/to/file</pre>
<p><a href="http://www.gnu.org/manual/gawk/html_node/Command-Line-Field-Separator.html">gawk manual: 3.5.3 Setting FS from the Command Line</a></p>
<p>手慣れたスクリプト言語でワンライナーを書いてしまうべきか数秒まよったが、なんとなく <a href="http://en.wikipedia.org/wiki/AWK">awk </a>を使うことに。</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[[awk] Print selective columns and watch for changes]]></title>
<link>http://nixtricks.wordpress.com/2009/09/26/awk-print-selective-columns-and-watch-for-changes/</link>
<pubDate>Sat, 26 Sep 2009 09:29:57 +0000</pubDate>
<dc:creator>kousik</dc:creator>
<guid>http://nixtricks.wordpress.com/2009/09/26/awk-print-selective-columns-and-watch-for-changes/</guid>
<description><![CDATA[Print columns 1, 5 and then 2, put a colon, and then print column 10 of a line that matches pattern ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Print columns 1, 5 and then 2, put a colon, and then print column 10 of a line that matches <em>pattern</em> from the file <em>columns.txt</em>:</p>
<div style="border:1px dotted black;padding:1em;"><code> $ awk '/<em>pattern</em>/ {print $1, $5, $2, ": ", $10}' <em>columns.txt</em><br />
</code></div>
<p><span style="color:#ffffff;">.</span><br />
<strong>Protecting the special meaning of the single quotes and curly braces</strong><br />
I came across this situation when I was trying to <code>watch</code> the above command as well as two other commands (say, <code>command1</code> and <code>command2</code>) at the same time. The correct way to do that is by properly protecting the meaning of the special characters in the above <code>awk</code> invocation:</p>
<div style="border:1px dotted black;padding:1em;"><code> $ watch -d -n 20 "command1; command2; awk '"'/<em>pattern</em>/ {print $1, $5, $2, ": ", $10}'"' <em>columns.txt</em>"</code></div>
<p>.<br />
<strong>N.B.</strong> The &#8220;<code>-d</code>&#8221;flag highlights the changes, whereas the &#8220;<code>-n 20</code>&#8221; flag causes the above to watch every 20 seconds.</p>
<p>Just for the heck of it, let me put the full command that I was actually using:</p>
<div style="border:1px dotted black;padding:1em;"><code> $ watch -d -n 20 "ps aux &#124; grep -i columbus &#124; grep -v grep &#38;&#38; echo;  tail WORK/ciudgsm &#38;&#38; echo &#38;&#38; grep bond output.log &#124; tail -13 &#38;&#38; echo &#38;&#38; awk '"'/state # 1/ {print $3,$4,$5,": ", $10}'"' output.log &#38;&#38; echo; awk '"'/state # 2/ {print $3,$4,$5,": ", $10}'"' output.log &#38;&#38; head curr_iter"<br />
</code></div>
<p>(suggestions for making the above shorter, other than by aliasing, are most welcome!).</p>
<p><strong>Reference: </strong> <a href="http://www.vectorsite.net/tsawk.html">here</a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to do line substitution in files for linux routers?]]></title>
<link>http://poundcomment.wordpress.com/2009/09/23/how-to-do-line-substitution-in-files-for-linux-routers/</link>
<pubDate>Wed, 23 Sep 2009 12:00:51 +0000</pubDate>
<dc:creator>coder_commenter</dc:creator>
<guid>http://poundcomment.wordpress.com/2009/09/23/how-to-do-line-substitution-in-files-for-linux-routers/</guid>
<description><![CDATA[In many situations, this is a trivial task: create a simple regex script in Perl (or Python), and ex]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In many situations, this is a trivial task: create a simple regex script in Perl (or Python), and execute it. However, with linux routers it becomes a bit tricky. Usually by default these routers do not have high-level scripting languages installed due to limited resources. It is possible to add them by extending the diskspace through external means (like USB or SD card), but generally unless the user needs to use scripts extensively it isn&#8217;t necessary. There are several means to do substitution here.</p>
<h4>Method #1: sed substitution.</h4>
<p style="padding-left:30px;">Sed substitution is the easiest method to do line substitution, and the most recommended method. However, the cryptic syntax is not very user-friendly, especially those unfamiliar to sed (yet familiar to generic regex). To do a simple  substitution, use the following syntax:</p>
<p style="padding-left:30px;"><code># Syntax to do substitution in the file.<br />
&#62; sed -i 's/text1/text2/' file<br />
</code></p>
<p style="padding-left:30px;">This will take all instances of &#8216;text1&#8242; and replaces it with &#8216;text2&#8242; in the file. Note that the &#8216;-i&#8217; means that it will change the file directly instead of printing the changes to stdout. This only does pure substitution, not line substitution. To do that, we need to use the &#8216;c\&#8217; option instead of the &#8217;s&#8217; option at the beginning of the string. See below:</p>
<p style="padding-left:30px;"><code># Syntax to do line substitution in the file, trying to match text1 with text2.<br />
&#62; sed -i '/text1/ c\ text2' file<br />
</code></p>
<p style="padding-left:30px;">Note that the &#8217;s&#8217; in the beginning of the string is no longer there. There are actually several options in this same format. &#8216;i\&#8217; will insert the line before the matched text1, and &#8216;a\&#8217; will append the line after the matched text1.</p>
<p style="padding-left:30px;">In a practical example, openWRT tends to not setup the firewall (iptables) properly. When using the UI, it tends to comment out the option to include firewall.user. So I used this simple sed statement to uncomment the option whenever the firewall is changed:</p>
<p style="padding-left:30px;"><code># Uncomment out the etc/firewall.user<br />
&#62; sed -i '/option.*\/etc\/firewall.user/ c\ option path /etc/firewall.user' /etc/config/firewall<br />
</code></p>
<p style="padding-left:30px;">This will make:</p>
<p style="padding-left:30px;"><em>/etc/config/firewall</em></p>
<pre>...
# option path '/etc/firewall.user'
...</pre>
<p style="padding-left:30px;">look like this:</p>
<p style="padding-left:30px;"><em>/etc/config/firewall</em></p>
<pre>...
 option path /etc/firewall.user
...</pre>
<p style="padding-left:30px;">(A simplier way is to actually go to the source code and fix the issue, but this example is meant to show how this could be useful).</p>
<p style="padding-left:30px;">To understand more about how to use sed, see below references.</p>
<h4>Method #2: awk substitution.</h4>
<p style="padding-left:30px;">Another way to do substitution is to do it through awk. If sed seems cryptic, awk is even more so. Though the language is very powerful and there are many methods to accomplish this through awk, here is a simple example that does the line replacement:</p>
<p style="padding-left:30px;"><code># Replace line containing text1 with text2.<br />
&#62; awk '/text1/ {print "text2"; next} /.*/ print ;}' file &#62; tmp.file<br />
&#62; mv tmp.file file<br />
</code></p>
<p style="padding-left:30px;">One disadvantage is that you can&#8217;t replace the file directly (since it seems to erase the file completely).</p>
<p style="padding-left:30px;">Some explanation over the awk syntax: AWK goes through a pattern-action routine. If /pattern/ matches, then {run action}. So if it matches /text1/, then it&#8217;ll {print &#8220;text2&#8243;}. The next means to skip to the next line, or otherwise it&#8217;ll continue to try to match against other patterns. The second pattern (/.*/) is there to match all the other lines, and print as normal.</p>
<p style="padding-left:30px;">So, using the above openWRT situation, an awk statement will look like this:</p>
<p style="padding-left:30px;"><code># Uncomment out the etc/firewall.user<br />
&#62; </code><code>awk '/option.*\/\etc\/firewall.user/ {print "option path /etc/firewall.user"; next} /.*/ {print ;}' /etc/config/firewall &#62; tmp<br />
&#62; mv -f tmp /etc/config/firewall<br />
</code></p>
<p style="padding-left:30px;">More information about awk can be found in the references below.</p>
<h4>Method #3: Perl substitution.</h4>
<p style="padding-left:30px;">For those who really need to use Perl or just so happen to have it installed, here is how to do line substitution in Perl:</p>
<p style="padding-left:30px;"><code># Replace line containing text1 with text2.<br />
&#62; perl -pi -e 's/^.*test1.*/test2/' file<br />
</code></p>
<p style="padding-left:30px;">Like in sed, the -i means to edit directly into the file. The -p allows to read in file as input, and -e executes the commands the quotes. To run the openWRT example above, it would look something like this:</p>
<p style="padding-left:30px;"><code># Uncomment out the etc/firewall.user<br />
&#62; </code><code>perl -pi -e 's/.*option.*\/etc\/firewall.user.*/option path \/etc\/firewall.user/' /etc/config/firewall<br />
</code></p>
<h4>Method #4: Python substitution.</h4>
<p style="padding-left:30px;"><code>This section will be added later once I have a better understanding of python. Unfortunately, the language is elusive to me, so there's room for improvement to understand how to work with this language.<br />
</code></p>
<h4>References:</h4>
<p style="padding-left:30px;">Sed: <a href="http://www.grymoire.com/Unix/Sed.html#uh-42">An Introduction and Tutorial</a><br />
AWK: <a href="http://blog.dipinkrishna.info/2009/08/awk-find-and-replace-text.html">Find and Replace text</a><br />
AWK: <a href="http://www.daemon-systems.org/man/awk.1.html">Manpage for awk(1)</a><br />
Perl: <a href="http://www.perl.com/pub/a/2004/08/09/commandline.html?page=2">Command-Line Options</a><br />
Perl: <a href="http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#DoingSubstitutions">Regular Expressions</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Awk Moments with Co-Workers, Vol. 1]]></title>
<link>http://laurenrerickson.wordpress.com/2009/08/26/awk-moments-with-co-workers-vol-1/</link>
<pubDate>Wed, 26 Aug 2009 19:47:38 +0000</pubDate>
<dc:creator>laurenrerickson</dc:creator>
<guid>http://laurenrerickson.wordpress.com/2009/08/26/awk-moments-with-co-workers-vol-1/</guid>
<description><![CDATA[Guy Co-Worker: Umm, Lauren, will you help me? Me: Sure. GCW: Will you grab these keys out of my pock]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Guy Co-Worker: Umm, Lauren, will you help me?<br />
Me: Sure.<br />
GCW: Will you grab these keys out of my pocket? (shifts back pocket toward me)</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Secondary Offerings Run At Market Flood Rates (MPEL, GSIC, AWK, GLDD, YSI, TBBK, HMPR, SBCF, CADE, UMPQ)]]></title>
<link>http://247wallst.com/2009/08/13/secondary-offerings-run-at-market-flood-rates-mpel-gsic-awk-gldd-ysi-tbbk-hmpr-sbcf-cade-umpq/</link>
<pubDate>Thu, 13 Aug 2009 15:52:16 +0000</pubDate>
<dc:creator>247wallst</dc:creator>
<guid>http://247wallst.com/2009/08/13/secondary-offerings-run-at-market-flood-rates-mpel-gsic-awk-gldd-ysi-tbbk-hmpr-sbcf-cade-umpq/</guid>
<description><![CDATA[It is one thing that we had two fairly large IPOs this week.  But the flood of public secondary stoc]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a rel="attachment wp-att-43994" href="http://247wallst.com/2009/08/13/secondary-offerings-run-at-market-flood-rates-mpel-gsic-awk-gldd-ysi-tbbk-hmpr-sbcf-cade-umpq/money-stack-image-120/"><img class="alignleft size-full wp-image-43994" title="money-stack-image" src="http://247wallst.wordpress.com/files/2009/08/money-stack-image13.jpg" alt="money-stack-image" width="88" height="88" /></a>It is one thing that we had two fairly large IPOs this week.  But the flood of public secondary stock offerings is almost running at alarming levels when you consider that these share sales are after such a large run-up in the markets.  Melco Crown Entertainment Ltd. (NASDAQ: MPEL) $200 million and GSI Commerce Inc. (NASDAQ: GSIC) (and holders) sold about $201 million in secondary offerings this morning.  Other stocks in offerings are scheduled from American Water Works Co. (NYSE: AWK), Great Lakes Dredge &#38; Dock Corp. (NASDAQ: GLDD), and U-Store-It Trust (NYSE: YSI).  Then there is the flood of regional and community banks selling stock.</p>
<p>Details are as follows:<br />
<!--more--><br />
American Water Works Co. (NYSE: AWK) is on deck with German-parent RWE selling another 30 million shares via Bank of America Merrill Lynch, Citigroup and Goldman Sachs.  With shares close to $19.00 today, this generates a $570 million estimates take.</p>
<p>Great Lakes Dredge &#38; Dock Corp. (NASDAQ: GLDD) is on deck with some 12.5 million shares being sold through Barclays Capital and Bank of America Merrill Lynch.  This should come to roughly $75 million being raised based on today&#8217;s price.</p>
<p>U-Store-It Trust (NYSE: YSI) is set to sell 22 million shares through  Bank of America Merrill Lynch and Wells Fargo and this deal is expected to raise close to $110 million based on today&#8217;s price.</p>
<p>Then there are the regional and community banks that we have seen from Dandler O&#8217;Neill.  The Bancorp Bank (NASDAQ: TBBK) is on deck to sell roughly $50 million worth of shares through Sandler O&#8217;Neill.  Hampton Roads Bancshares Inc. (NASDAQ: HMPR) is expected to sell some 32 million shares through Sandler O&#8217;Neill and should raise roughly $140 million based on today&#8217;s price.  Seacoast Banking Corp. of Florida (NASDAQ: SBCF) is expected to sell about 28 million shares also through Sandler O&#8217;Neill and will bring in close to $70 million based on today&#8217;s prices.</p>
<p>Two more banking deals are also on deck that will either come tonight or perhaps next week.  Cadence Financial Corp. (NASDAQ: CADE) is expected to sell 31.5 million shares through FBR Capital Markets in an effort to raise roughly $55 million based upon today&#8217;s price.  Be advised, Cadence is extremely think trading volume.  Umpqua Holdings Corp. (NASDAQ: UMPQ) is expected to sell some $175 million in common stock via JPMorgan and others including KBW.</p>
<p>When we tally all of this up, it comes to more than $1.6 billion in secondary offerings just between today and what may come tomorrow.  That cash has to come from somewhere and generally has to stay in the stock for at least a little bit of time.</p>
<p>You can <a href="http://247wallst.com/page/free-newsletter/" target="_blank">join our open email distribution list</a> if you like to hear about secondary offerings, IPOs, Warren Buffett and other guru activities, mergers, key daily analyst reports, and other top trading and investing issues.</p>
<p>JON C. OGG<br />
AUGUST 13, 2009</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Dig Into Unix: Sed and Awk]]></title>
<link>http://theappleblog.com/2009/08/11/dig-into-unix-sed-and-awk/</link>
<pubDate>Tue, 11 Aug 2009 20:37:46 +0000</pubDate>
<dc:creator>Jon Buys</dc:creator>
<guid>http://theappleblog.com/2009/08/11/dig-into-unix-sed-and-awk/</guid>
<description><![CDATA[Time again to pop a shell and dig into the deep, geeky Unix internals of OS X with Dig Into Unix. To]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="alignright size-full wp-image-24267" title="Terminal" src="http://gigapple.wordpress.com/files/2009/05/terminal.png" alt="Terminal" width="133" height="118" /></p>
<p class="excerpt">Time again to pop a shell and dig into the deep, geeky Unix internals of OS X with <a href="http://theappleblog.com/tag/dig-into-unix/">Dig Into Unix</a>. Today we are going to look at two top-shelf power tools for text editing: <a href="http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/sed.1.html">sed</a> and <a href="http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/awk.1.html">awk</a>.</p>
<p>Sed is a Stream EDitor, and if you recall our <a href="http://theappleblog.com/2009/07/01/dig-into-unix-standard-streams/">previous</a> Dig Into Unix installment concerning standard streams, you&#8217;ll understand that the streams we are talking about are actually just text from one source or another. Sed&#8217;s bread and butter is text search and replace, very similary to the &#8220;Edit&#8221; and &#8220;Find&#8230;&#8221; functions in TextEdit and many other GUI text editors. Unlike those text editors though, sed, by default, will write its output to the screen, or stdout. <!--more--></p>
<p>As an example, try some basic operations on this string of text:<br />
<code>The quick brown fox jumped over the lazy dog's back.</code></p>
<p>Save the string of text as a file named test.txt, and type this into the Terminal:<br />
<code>sed s/quick/slow/g test.txt</code></p>
<p>The fox is now slow on the screen, but not changed in the file itself. To follow the stream, the text came from the file, through sed, and to the screeen. The best set of examples I&#8217;ve found for getting right into sed and starting to play with it is the collection of <a href="http://sed.sourceforge.net/sed1line.txt">sed one liners</a> hosted at Sourceforge.</p>
<p>Personally, I use sed when I&#8217;ve got a large number of configuration files that need to be edited. For example, it might be decided that we do not need our <a href="http://www.nagios.org/">Nagios</a> monitoring system alerting on the a certain statistic. I could go into 100 different files and perform the same action on all of them, or I could rely on a simple shell script and sed to do it for me.</p>
<p><code><br />
for each in `ls *.cfg`; do<br />
mv $each $each.bak #Safety First!<br />
sed '30,35s/^/\#/g' $each.bak &#62; $each<br />
done<br />
</code></p>
<p>This will plow through all of the config files in a certain directory and add a # sign at the beginning of lines 30 through 35, commenting those lines out. Then I can restart Nagios, and if all goes well, delete all of the .bak files created as backups by the script.</p>
<p>While sed operates on lines and regular expressions (the subject of a future Dig Into Unix article!), awk works with <em>fields</em>. When given a stream of text, either from a text file or piped in from another application, awk can manipulate the text and rearrange the words. By default, awk separates the text fields by a space character, but you can use any other character you&#8217;d like.</p>
<p>Like sed, awk also has a great collection of <a href="http://www.pement.org/awk/awk1line.txt">one liners</a>, this collection here is a great resource collected by Eric Pement. In my day to day activities, I call on awk when I want to format text for a report or to be input into another application.</p>
<p>To use our quick brown fox example again, we can print only the fourth, third, and second words, in reverse order, with this command:<br />
<code>awk '{ print $4, $3, $2 }' test</code></p>
<p>That will print out &#8220;fox brown quick&#8221;. Not very practical or useful. Something more practical might be to manipulate a list of comma separated values. Using the &#8220;-F&#8221; flag in awk, you can tell awk to separate it&#8217;s fields based on the comma, as in:<br />
<code>awk -F, '{ print $1 }' test</code></p>
<p>Since there are no commas in the test file, this will print the entire string of text. So, we could run this command to take care of that:<br />
<code>sed s/\ /,/g test &#62; test2</code></p>
<p>This will use sed to replace all spaces with commas. The backslash is there to escape a special character, so the space is interpreted literally and not as part of a command. Now, you could use awk to manipulate the string of text as needed.<br />
<code>awk -F, '{ print $7, $8, $9, $10, $5, $6, $1, $2, $3, $4 " did" }' test2</code></p>
<p>This article has just barely skimmed the surface of what sed and awk can do. There are some rather hefty books dedicated to the pair, <a title="sed &#38; awk &#124; O'Reilly Media" href="http://oreilly.com/catalog/9781565922259/">this one</a> from O&#8217;Reilly has been on my desk for years now. Awk is an entire programming language, but the point of this series is not to teach the in-depth details, it&#8217;s just to get your feet wet, and maybe, just maybe leave you thirsting for more. The real rub is that everything that sed and awk can do can also be done, at times more efficiently, with the practical extraction and report language&#8230;better known as Perl, which is the subject of a future Dig Into Unix article.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[AWK + PIX/ASA/IOS syslog]]></title>
<link>http://stealingfocus.wordpress.com/2009/08/06/awk-pixasaios-syslog/</link>
<pubDate>Thu, 06 Aug 2009 01:12:39 +0000</pubDate>
<dc:creator>killerkadoogan</dc:creator>
<guid>http://stealingfocus.wordpress.com/2009/08/06/awk-pixasaios-syslog/</guid>
<description><![CDATA[Here is something I emailed myself from a previous job, 2 short AWK scripts for parsing Cisco IOS an]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p style="font-size:11px;line-height:1.4em;margin:0 0 18px;padding:0 24px 0 0;">Here is something I emailed myself from a previous job, 2 short AWK scripts for parsing Cisco IOS and PIX/ASA syslogs into lists of source/destination IPs and dest Ports. Very handy for trying to figure out just what’s been going through your devices.</p>
<p style="font-size:11px;line-height:1.4em;margin:0 0 18px;padding:0 24px 0 0;">The PIX/ASA logs need to be on informational (the level where it shows build and teardown messages, and the IOS logs need to have tcp/udps any any with gt’s in them, so ports are listed. That is to say, if you do IP any any log, it will show the port as (0), the router doesn’t inspect down to that level with IP to return a port number.</p>
<p style="font-size:11px;line-height:1.4em;margin:0 0 18px;padding:0 24px 0 0;">So the logging ACL needs to be something like this:</p>
<pre style="font-size:9px;line-height:1.4em;margin:0;padding:0;">ip access-list extended PATRICK
permit tcp any gt 0 any gt 0 log
permit tcp any gt 0 any gt 0 log
permit icmp any any log
permit ip any any</pre>
<pre style="font-size:9px;line-height:1.4em;margin:0;padding:0;"># these commands AWKs all the build connection lines:

/Built/ {if (($8 ~ /^TCP$/ &#124;&#124; $8 ~ /^UDP$/) &#38;&#38; $7 ~ /^outbound$/) print "src",substr($16,1+ index($16,"("),-2 + index($16,"/")),"dst",substr($13,1+ index($13,"("),-2 + index($13,"/")),$8,substr($12,1+index($12,"/"),5)}
/Built/ {if (($8 ~ /^TCP$/ &#124;&#124; $8 ~ /^UDP$/) &#38;&#38; $7 ~ /^inbound$/) print "src",substr($13,1+ index($13,"("),-2 + index($13,"/")),"dst",substr($16,1+ index($16,"("),-2 + index($16,"/")),$8,substr($15,1+index($15,"/"),5)}
/Built/ {if ($8 ~ /^ICMP$/) print "src",substr($14,1+ index($14,"("),-1 + index($14,"/")),"dst",substr($12,0,-1 + index($12,"/")),$8}

# put the above into a file and reference it against the syslog folder you want to capture:

zcat /u01/networks/vpn-fw4.adl.nw.local/*gz &#124; <span style="font-size:9px;line-height:1.4em;margin:0;padding:0;">awk</span> -f search_pix3.<span style="font-size:9px;line-height:1.4em;margin:0;padding:0;">awk</span> &#62; pix3output

# then sort and count the unique lines:

sort pix3output &#124; uniq -c
<pre style="font-size:9px;line-height:1.4em;margin:0;padding:0;">script for parsing router syslogs:

/SEC-6-IPACCESSLOG/ {
        if ($12 ~ /^log_hw_ports_inbound$/ &#38;&#38; ($14 ~ /^tcp$/ &#124;&#124; $14 ~ /^udp$/)) \
        print \
        $12,$14,"src",substr($15,0,-1 + index($15,"\(")), \
        "dst",substr($17,0,-1+index($17,"\(")),substr($17,1+index($17,"("),index($17,")")-index($17,"(")-1);
        #
        if ($12 ~ /^log_hw_ports_outbound$/ &#38;&#38; ($14 ~ /^tcp$/ &#124;&#124; $14 ~ /^udp$/)) \
        print \
        $12,$14,"src",substr($15,0,-1 + index($15,"\(")), \
        "dst",substr($17,0,-1+index($17,"\(")),substr($17,1+index($17,"("),index($17,")")-index($17,"(")-1);
        #
        if ($14 ~ /^icmp$/) \
        print \
        $12,$14,"src",$15,"dst",$17,$18</pre>
</pre>
<p style="font-size:11px;line-height:1.4em;margin:0 0 18px;padding:0 24px 0 0;">if anyone reads this and needs some help implementing it, I can try to explain it, it made sense to me at the time!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[What is awk &amp; sed?]]></title>
<link>http://uccirl.wordpress.com/2009/08/01/64/</link>
<pubDate>Sat, 01 Aug 2009 14:38:05 +0000</pubDate>
<dc:creator>Kratip</dc:creator>
<guid>http://uccirl.wordpress.com/2009/08/01/64/</guid>
<description><![CDATA[Meaning of awk &amp; sed from Wikipedia &#8220;AWK is a language for processing files of text. A fil]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Meaning of awk &#38; sed from Wikipedia</p>
<p>&#8220;<strong><span style="color:#ff0000;">AWK</span></strong> is a language for processing files of text. A file is treated as a sequence of records, and by default each line is a record. Each line is broken up into a sequence of fields, so we can think of the first word in a line as the first field, the second word as the second field, and so on. An AWK program is of a sequence of pattern-action statements. AWK reads the input a line at a time. A line is scanned for each pattern in the program, and for each pattern that matches, the associated action is executed.&#8221; &#8211; Alfred V. Aho</p>
<p>&#8220;<strong><span style="color:#ff0000;">SED</span></strong> (<em>stream editor</em>) is a <a title="Unix" href="/wiki/Unix">Unix</a> utility that (a) parses text files and (b) implements a <a title="Programming language" href="/wiki/Programming_language">programming language</a> which can apply textual transformations to such files. It reads input files line by line (sequentially), applying the operation which has been specified via the command line (or a <em>sed script</em>), and then outputs the line.&#8221;</p>
<p><em><span style="color:#339966;">An introductory book</span></em>:  Dougherty, D. &#38; Robbins, A. (1997). <strong>Sed &#38; awk</strong>. 2nd. ed. Sebastopol, CA : O&#8217;Reilly.<br />
<a href="http://books.google.co.nz/books?id=m4ZzElQZxcoC&#38;lpg=PP1&#38;dq=AWK%20%26%20SED%20book&#38;pg=PP1#v=onepage&#38;q=&#38;f=false"><img class="alignleft size-full wp-image-67" title="sed &#38; awk" src="http://uccirl.wordpress.com/files/2009/08/awkbooks2.jpg" alt="sed &#38; awk" width="61" height="80" /></a></p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
