<?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/"
	>

<channel>
	<title>MemoSoup &#187; output</title>
	<atom:link href="http://www.memosoup.com/tag/output/feed" rel="self" type="application/rss+xml" />
	<link>http://www.memosoup.com</link>
	<description>Mix of the things I always forget</description>
	<lastBuildDate>Fri, 30 Jul 2010 15:59:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Redirect script output to the log</title>
		<link>http://www.memosoup.com/20090913/redirect-script-output-to-the-log.html</link>
		<comments>http://www.memosoup.com/20090913/redirect-script-output-to-the-log.html#comments</comments>
		<pubDate>Sun, 13 Sep 2009 17:29:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=87</guid>
		<description><![CDATA[<p>If the whole output of the complex script should be redirected to the log, the following trick could be used.</p>
if &#91; &#34;$1&#34; != &#34;-log&#34; &#93; ; then &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; 
&#160; &#160;$0 -log &#34;$@&#34; 2&#62;&#38;1 &#124; tee the_log_file.$$.log &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>If the whole output of the complex script should be redirected to the log, the following trick could be used.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;-log&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp;<span style="color: #007800;">$0</span> <span style="color: #660033;">-log</span> <span style="color: #ff0000;">&quot;$@&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> the_log_file.<span style="color: #007800;">$$</span>.log &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The log file for the current session: the_log_file.$$.log&quot;</span> &nbsp;<br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #000000; font-weight: bold;">fi</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #7a0874; font-weight: bold;">shift</span> &nbsp;<span style="color: #666666; font-style: italic;"># remove &quot;-log&quot; parameter</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090913/redirect-script-output-to-the-log.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Print the PATH directories in the readable format</title>
		<link>http://www.memosoup.com/20090912/print-the-path-directories-in-the-readable-format.html</link>
		<comments>http://www.memosoup.com/20090912/print-the-path-directories-in-the-readable-format.html#comments</comments>
		<pubDate>Sat, 12 Sep 2009 18:55:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[PATH]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=69</guid>
		<description><![CDATA[echo $PATH&#124; awk -v RS=&#34;:&#34; '{ print $0 }'

echo $LD_LIBRARY_PATH &#124;awk -v RS=&#34;:&#34; '{ system ( &#34;ls -rltd &#34; $0 ) }'
<p>Warning!
As far as the option &#8216;-v&#8217; is used, the new awk(nawk in some systems) should be used.</p>
<p>To check if the new version of awk is installed:</p>
awk 1 /dev/null
<p>The output will be empty for new awk.
You [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">RS</span>=<span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'{ print $0 }'</span><br />
<br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$LD_LIBRARY_PATH</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">RS</span>=<span style="color: #ff0000;">&quot;:&quot;</span> <span style="color: #ff0000;">'{ system ( &quot;ls -rltd &quot; $0 ) }'</span></div></div>
<p><em>Warning!</em><br />
As far as the option &#8216;-v&#8217; is used, the new awk(<strong>nawk</strong> in some systems) should be used.</p>
<p>To check if the new version of awk is installed:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</div></div>
<p>The output will be empty for new awk.<br />
You have the old awk, if the output is something like</p>
<blockquote><p>
awk: syntax error near line 1
</p></blockquote>
<p>In this case <strong>nawk</strong> should be used instead <strong>awk</strong></p>
<p><strong>MS-DOS</strong> modification: echo %PATH% | awk -v RS=&#8221;;&#8221; &#8220;{ print $0 }&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090912/print-the-path-directories-in-the-readable-format.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sybase sp_freedevice procedure</title>
		<link>http://www.memosoup.com/20090912/sybase-sp_freedevice-procedure.html</link>
		<comments>http://www.memosoup.com/20090912/sybase-sp_freedevice-procedure.html#comments</comments>
		<pubDate>Fri, 11 Sep 2009 23:37:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Sybase]]></category>
		<category><![CDATA[device]]></category>
		<category><![CDATA[output]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=36</guid>
		<description><![CDATA[<p>Only the short info about Sybase database devices.
Parameters:
 min_space  &#8211; minimum of required space (i.e. 40 will display the devices with >=40M free space)
 the_name  &#8211; the template for the device name (i.e. %mast% will display only master device)</p>
<p>Warning! It was not tested for all possible configurations, so the result could be incorrect on [...]]]></description>
			<content:encoded><![CDATA[<p>Only the short info about <strong>Sybase database devices</strong>.<br />
Parameters:<br />
 <em>min_space </em> &#8211; minimum of required space (i.e. 40 will display the devices with >=40M free space)<br />
 <em>the_name</em>  &#8211; the template for the device name (i.e. %mast% will display only master device)</p>
<p><strong>Warning! </strong>It was not tested for all possible configurations, so the result could be incorrect on some OS.</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">create</span> <span style="color: #0000FF;">procedure</span> sp_freedevice<br />
@min_space <span style="color: #0000FF;">int</span> <span style="color: #808080;">=</span> null,<br />
@the_name <span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">40</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> null<br />
<span style="color: #0000FF;">as</span><br />
<span style="color: #0000FF;">begin</span><br />
<br />
<span style="color: #0000FF;">declare</span> @numpgsmb <span style="color: #0000FF;">integer</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">/* Number of 'virtual' Pages per Megabytes */</span><br />
<span style="color: #0000FF;">select</span> @numpgsmb <span style="color: #808080;">=</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">1048576</span>. <span style="color: #808080;">/</span> @@pagesize<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">select</span> <span style="color: #FF0000;">&quot;phyname&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">40</span><span style="color: #808080;">&#41;</span>, d.<span style="color: #202020;">phyname</span><span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;name&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">28</span><span style="color: #808080;">&#41;</span>,d.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;d_size&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">6</span><span style="color: #808080;">&#41;</span>,<span style="color: #808080;">&#40;</span><span style="color: #000;">1</span> <span style="color: #808080;">+</span> d.<span style="color: #202020;">high</span> <span style="color: #808080;">-</span> d.<span style="color: #202020;">low</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;d_used&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">6</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF00FF;">sum</span><span style="color: #808080;">&#40;</span>u.<span style="color: #0000FF;">size</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> ,<br />
<span style="color: #FF0000;">&quot;d_free&quot;</span><span style="color: #808080;">=</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span> <span style="color: #808080;">+</span> d.<span style="color: #202020;">high</span> <span style="color: #808080;">-</span> d.<span style="color: #202020;">low</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #FF00FF;">sum</span><span style="color: #808080;">&#40;</span>u.<span style="color: #0000FF;">size</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span>,<br />
vdevno<span style="color: #808080;">=</span>d.<span style="color: #202020;">low</span><span style="color: #808080;">/</span><span style="color: #FF00FF;">power</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>,<span style="color: #000;">24</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">255</span><br />
<span style="color: #0000FF;">into</span> #free_device_all_tbl<br />
<span style="color: #0000FF;">from</span> master..<span style="color: #202020;">sysusages</span> u, master..<span style="color: #202020;">sysdevices</span> d<br />
<span style="color: #0000FF;">where</span> u.<span style="color: #202020;">vstart</span> between d.<span style="color: #202020;">low</span> and d.<span style="color: #202020;">high</span><br />
and d.<span style="color: #202020;">status</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">2</span> <span style="color: #808080;">=</span> <span style="color: #000;">2</span> <br />
<span style="color: #0000FF;">group</span> <span style="color: #0000FF;">by</span> d.<span style="color: #202020;">name</span><br />
<br />
<span style="color: #0000FF;">select</span> <br />
vdevno<span style="color: #808080;">=</span>low<span style="color: #808080;">/</span><span style="color: #FF00FF;">power</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span>,<span style="color: #000;">24</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">255</span>,<br />
<span style="color: #FF0000;">&quot;Physical Name&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">40</span><span style="color: #808080;">&#41;</span>, d.<span style="color: #202020;">phyname</span><span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;Device Name&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">28</span><span style="color: #808080;">&#41;</span>,d.<span style="color: #202020;">name</span><span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;Size&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">6</span><span style="color: #808080;">&#41;</span>,<span style="color: #808080;">&#40;</span><span style="color: #000;">1</span> <span style="color: #808080;">+</span> d.<span style="color: #202020;">high</span> <span style="color: #808080;">-</span> d.<span style="color: #202020;">low</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;Used&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">6</span><span style="color: #808080;">&#41;</span>,<span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>,<br />
<span style="color: #FF0000;">&quot;Free&quot;</span><span style="color: #808080;">=</span><span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">6</span><span style="color: #808080;">&#41;</span>,<span style="color: #808080;">&#40;</span><span style="color: #000;">1</span> <span style="color: #808080;">+</span> d.<span style="color: #202020;">high</span> <span style="color: #808080;">-</span> d.<span style="color: #202020;">low</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">from</span> master..<span style="color: #202020;">sysdevices</span> d<br />
<span style="color: #0000FF;">where</span> d.<span style="color: #202020;">name</span> not in <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">select</span> tmp.<span style="color: #202020;">name</span> <span style="color: #0000FF;">from</span> #free_device_all_tbl tmp<span style="color: #808080;">&#41;</span><br />
and d.<span style="color: #202020;">status</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">2</span> <span style="color: #808080;">=</span> <span style="color: #000;">2</span><br />
and <span style="color: #808080;">&#40;</span> @min_space <span style="color: #0000FF;">is</span> null or <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span> <span style="color: #808080;">+</span> d.<span style="color: #202020;">high</span> <span style="color: #808080;">-</span> d.<span style="color: #202020;">low</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">/</span> @numpgsmb<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;=</span> @min_space <span style="color: #808080;">&#41;</span><br />
and <span style="color: #808080;">&#40;</span> @the_name <span style="color: #0000FF;">is</span> null or d.<span style="color: #202020;">phyname</span> like @the_name or d.<span style="color: #202020;">name</span> like @the_name<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">union</span><br />
<span style="color: #0000FF;">select</span> vdevno , &nbsp;phyname , name , d_size , d_used , <span style="color: #0000FF;">convert</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">varchar</span><span style="color: #808080;">&#40;</span><span style="color: #000;">6</span><span style="color: #808080;">&#41;</span>, d_free<span style="color: #808080;">&#41;</span> <br />
<span style="color: #0000FF;">from</span> #free_device_all_tbl<br />
<span style="color: #0000FF;">where</span> <span style="color: #808080;">&#40;</span> @min_space <span style="color: #0000FF;">is</span> null or d_free <span style="color: #808080;">&gt;=</span> @min_space <span style="color: #808080;">&#41;</span><br />
and <span style="color: #808080;">&#40;</span> @the_name <span style="color: #0000FF;">is</span> null or phyname like @the_name or name like @the_name<span style="color: #808080;">&#41;</span><br />
<span style="color: #0000FF;">order</span> <span style="color: #0000FF;">by</span> <span style="color: #000;">1</span><br />
<br />
<span style="color: #0000FF;">end</span><br />
go</div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090912/sybase-sp_freedevice-procedure.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rev function and comma-separated output</title>
		<link>http://www.memosoup.com/20090912/rev-function-and-comma-separated-output.html</link>
		<comments>http://www.memosoup.com/20090912/rev-function-and-comma-separated-output.html#comments</comments>
		<pubDate>Fri, 11 Sep 2009 23:26:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=27</guid>
		<description><![CDATA[<p>Here is the shell command snippet to display comma-separated output:</p>
ls -lrt &#124; rev &#124; sed 's/\\([0-9][0-9][0-9]\\)/\\1,/g' &#124; rev &#124; sed 's/\\([\^0-9]\\),\\([0-9]\\)/\\1\\2/g;s/\^,\\([0-9]\\)/\\1/g'
<p>Example:
-rw-r&#8212;&#8211;   1 sybase   dba   1,572,872,192 Feb  2 07:09 master.dbf</p>
<p>Rev in awk</p>
#!/bin/ksh
nawk '{ l=length($0) ; for(i=l;i&#62;0;i--) { printf &#34;%s&#34;, substr($0,i,1) } ; print &#34;&#34; }'
<p>Rev function (absent on SunOS) :</p>
<p>(Warning! [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the shell command snippet to display <strong>comma-separated</strong> output:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-lrt</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">rev</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\\([0-9][0-9][0-9]\\)/\\1,/g'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">rev</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\\([\^0-9]\\),\\([0-9]\\)/\\1\\2/g;s/\^,\\([0-9]\\)/\\1/g'</span></div></div>
<p><strong>Example:</strong><br />
-rw-r&#8212;&#8211;   1 sybase   dba   <strong>1,572,872,192</strong> Feb  2 07:09 master.dbf</p>
<p><strong>Rev in awk</strong></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/ksh</span><br />
<span style="color: #c20cb9; font-weight: bold;">nawk</span> <span style="color: #ff0000;">'{ l=length($0) ; for(i=l;i&gt;0;i--) { printf &quot;%s&quot;, substr($0,i,1) } ; print &quot;&quot; }'</span></div></div>
<p><strong>Rev</strong> function (absent on SunOS) :</p>
<p>(<em>Warning!</em> Avoid spaces before #define &#8211; SunOS cc compiler doesn&#8217;t like them)</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339933;">#ident &nbsp;&quot;@(#)rev 1.0 &nbsp; &nbsp; 02/01/2006&quot;</span><br />
<span style="color: #339933;">#define MAX_STRING_SIZE 2000char version[] = &quot;rev v1.0 02/01/2006&quot;;</span><br />
<br />
main<span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">,</span>argv<span style="color: #009900;">&#41;</span><br />
<span style="color: #993333;">int</span> argc<span style="color: #339933;">;</span><br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #993333;">char</span> my_src<span style="color: #009900;">&#91;</span>MAX_STRING_SIZE<span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span><br />
<span style="color: #993333;">char</span> my_dst<span style="color: #009900;">&#91;</span>MAX_STRING_SIZE<span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span><br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>retCode <span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>tmp_s <span style="color: #339933;">;</span><br />
<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>filename<span style="color: #339933;">;</span><br />
FILE <span style="color: #339933;">*</span>fSource <span style="color: #339933;">;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* check command line arguments */</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'-'</span> <span style="color: #339933;">||</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #ff0000;">'/'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Usage: %s [file] <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
filename<span style="color: #339933;">=</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span><br />
fSource <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span> filename<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> fSource <span style="color: #339933;">==</span> NULL <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Can't open %s for reading<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> filename <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #808080; font-style: italic;">/* Using the standard input */</span><br />
fSource<span style="color: #339933;">=</span>stdin <span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #808080; font-style: italic;">/* if (argc &gt; 1) */</span><br />
<br />
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>retCode <span style="color: #339933;">=</span> fgets<span style="color: #009900;">&#40;</span> my_src<span style="color: #339933;">,</span> MAX_STRING_SIZE<span style="color: #339933;">,</span> fSource <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span>NULL <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
tmp_s<span style="color: #339933;">=</span>my_dst<span style="color: #339933;">+</span>MAX_STRING_SIZE<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">*</span>tmp_s<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span> i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> MAX_STRING_SIZE <span style="color: #339933;">&amp;&amp;</span> my_src<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> my_src<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">continue</span> <span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
tmp_s<span style="color: #339933;">--;</span><br />
<span style="color: #339933;">*</span>tmp_s<span style="color: #339933;">=</span>my_src<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
fprintf<span style="color: #009900;">&#40;</span> stdout<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> tmp_s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
fclose<span style="color: #009900;">&#40;</span> fSource <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<br />
fflush<span style="color: #009900;">&#40;</span> stdout <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #808080; font-style: italic;">/* main */</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090912/rev-function-and-comma-separated-output.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
