<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Random Thoughts &#187; scripts</title>
	<atom:link href="http://alexlurthu.wordpress.com/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://alexlurthu.wordpress.com</link>
	<description>Straight from the heart!</description>
	<lastBuildDate>Fri, 04 Dec 2009 20:54:08 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='alexlurthu.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/2e18259658cdc132622f409f5fd659ca?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Random Thoughts &#187; scripts</title>
		<link>http://alexlurthu.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://alexlurthu.wordpress.com/osd.xml" title="Random Thoughts" />
		<item>
		<title>Transforming Unix Timestamps in logs to date</title>
		<link>http://alexlurthu.wordpress.com/2007/07/22/transforming-unix-timestamps-in-logs-to-date/</link>
		<comments>http://alexlurthu.wordpress.com/2007/07/22/transforming-unix-timestamps-in-logs-to-date/#comments</comments>
		<pubDate>Sun, 22 Jul 2007 07:30:15 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://alexlurthu.wordpress.com/2007/07/22/transforming-unix-timestamps-in-logs-to-date/</guid>
		<description><![CDATA[Logfiles in older unix systems and monitoring systems just log the unix timestamp as the first field in the enteries. When we try to pull out data for a particular date, then it becomes tricky. The following code snippet will help pulling out data for a particular date quite easily
cat &#60;logfile&#62; &#124; perl -lane &#8216;$_=$F[0]; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexlurthu.wordpress.com&blog=1310241&post=12&subd=alexlurthu&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Logfiles in older unix systems and monitoring systems just log the unix timestamp as the first field in the enteries. When we try to pull out data for a particular date, then it becomes tricky. The following code snippet will help pulling out data for a particular date quite easily</p>
<p><strong>cat &lt;logfile&gt; | perl -lane &#8216;$_=$F[0]; s/\[//g ;s/\]//g; $date=`date -r $_` ; chomp($date); $out=$date . &#8221; &#8221; ; foreach(@F[1..scalar(@F)]) { chomp($_); $out=$out. $_.&#8221; &#8220;; }; print $out&#8217;</strong></p>
<p>After the perl snippet you can use commands like grep to filter out data based on date.</p>
<p><strong>alexj:~&gt; cat sample.log</strong></p>
<p>[1173070775] ns__stats&lt;207.126.228.89&gt;: 1.2.14<br />
[1173070832] ns__exec&lt;207.126.228.89&gt;: check_mysql_variable!-p=var!-u=check_var: code=0</p>
<p><strong>alexj:~&gt; cat sample.log | perl -lane &#8216;$_=$F[0]; s/\[//g ;s/\]//g; $date=`date -r $_` ; chomp($date); $out=$date . &#8221; &#8221; ; foreach(@F[1..scalar(@F)]) { chomp($_); $out=$out. $_.&#8221; &#8220;; }; print $out&#8217;</strong></p>
<p>Sun Mar  4 20:59:35 PST 2007 ns__stats&lt;207.126.228.89&gt;: 1.2.14<br />
Sun Mar  4 21:00:32 PST 2007 ns__exec&lt;207.126.228.89&gt;: check_mysql!-p=xx!-u=xx: code=0</p>
<p>Some alternate way to do it :</p>
<p>cat file | perl -p -e &#8217;s/^\[(\d+)\] /localtime($1)/e;&#8217;  //source philip</p>
<p>Code snippet just to pre append time to every line :</p>
<p>perl -p &#8216;print time, &#8221; &#8220;;&#8217;    //thanx philp</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/alexlurthu.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/alexlurthu.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexlurthu.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexlurthu.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexlurthu.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexlurthu.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexlurthu.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexlurthu.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexlurthu.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexlurthu.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexlurthu.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexlurthu.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexlurthu.wordpress.com&blog=1310241&post=12&subd=alexlurthu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexlurthu.wordpress.com/2007/07/22/transforming-unix-timestamps-in-logs-to-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9200ed713840b8e3b58d6c565a85e946?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Alex</media:title>
		</media:content>
	</item>
		<item>
		<title>Perl Snippet to extract first column</title>
		<link>http://alexlurthu.wordpress.com/2007/07/22/perl-snippet-to-extract-first-column/</link>
		<comments>http://alexlurthu.wordpress.com/2007/07/22/perl-snippet-to-extract-first-column/#comments</comments>
		<pubDate>Sun, 22 Jul 2007 07:25:14 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[extract]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://alexlurthu.wordpress.com/2007/07/22/perl-snippet-to-extract-first-column/</guid>
		<description><![CDATA[Requirement : Obtain line no and first field (if it is a number) from the following datafile
31726108012^Abicyclepatrolpuyallup^A0^B
31726228012^Acommercialguardseattlesecurity^A0^B
31726230512^Aconstructionguardkentsecurity^A0^B
31726241512^Aeventfederalguardsecurityway^A0^B
^A indicates ctrl + A
 perl -n -e &#8216;@line= split /^A/,$_ ; if (int($line[0]) != 0) {  print &#8220;$.  &#8221; . $line[0] .&#8221;\n&#8221; }&#8217; datafile
$. gives us the line no.
int(any non numeric value) will return 0.
To generate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexlurthu.wordpress.com&blog=1310241&post=11&subd=alexlurthu&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Requirement : Obtain line no and first field (if it is a number) from the following datafile</strong></p>
<p>31726108012^Abicyclepatrolpuyallup^A0^B<br />
31726228012^Acommercialguardseattlesecurity^A0^B<br />
31726230512^Aconstructionguardkentsecurity^A0^B<br />
31726241512^Aeventfederalguardsecurityway^A0^B</p>
<p>^A indicates ctrl + A</p>
<p><strong> perl -n -e &#8216;@line= split /^A/,$_ ; if (int($line[0]) != 0) {  print &#8220;$.  &#8221; . $line[0] .&#8221;\n&#8221; }&#8217; datafile</strong></p>
<p>$. gives us the line no.<br />
int(any non numeric value) will return 0.</p>
<p>To generate ctrl A use the following key combination ctrl + v + a. The output generated will be as follows :</p>
<p>5  31726228012<br />
6  31726230512<br />
7  31726241512<br />
8  31726254012</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/alexlurthu.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/alexlurthu.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alexlurthu.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alexlurthu.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alexlurthu.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alexlurthu.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alexlurthu.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alexlurthu.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alexlurthu.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alexlurthu.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alexlurthu.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alexlurthu.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alexlurthu.wordpress.com&blog=1310241&post=11&subd=alexlurthu&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://alexlurthu.wordpress.com/2007/07/22/perl-snippet-to-extract-first-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9200ed713840b8e3b58d6c565a85e946?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Alex</media:title>
		</media:content>
	</item>
	</channel>
</rss>