<?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; unix</title>
	<atom:link href="http://www.memosoup.com/tag/unix/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>Unix: get the file date</title>
		<link>http://www.memosoup.com/20090918/unix-get-the-file-date.html</link>
		<comments>http://www.memosoup.com/20090918/unix-get-the-file-date.html#comments</comments>
		<pubDate>Fri, 18 Sep 2009 15:08:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=132</guid>
		<description><![CDATA[ls -1 &#124; cpio -o &#124; cpio -ivt &#124; awk '{print $NF, $(NF-1), $(NF-4), $(NF-3) }'
<p>Warning: I/O expensive for the large files!</p>
<p>Perl:</p>
@a = localtime&#40;&#40;stat&#40;$my_file&#41;&#41;&#91;9&#93;&#41;; [...]]]></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: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cpio</span> <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cpio</span> <span style="color: #660033;">-ivt</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $NF, $(NF-1), $(NF-4), $(NF-3) }'</span></div></div>
<p><strong>Warning: </strong>I/O expensive for the large files!</p>
<p><strong>Perl:</strong></p>
<div class="codecolorer-container perl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">@a</span> <span style="color: #339933;">=</span> <a href="http://perldoc.perl.org/functions/localtime.html"><span style="color: #000066;">localtime</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/stat.html"><span style="color: #000066;">stat</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$my_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span><br />
<a href="http://perldoc.perl.org/functions/printf.html"><span style="color: #000066;">printf</span></a> <span style="color: #ff0000;">&quot;%02d%02d%02d&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">@a</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090918/unix-get-the-file-date.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>grep in find command: how to display file names</title>
		<link>http://www.memosoup.com/20090913/grep-in-find-command-how-to-display-file-names.html</link>
		<comments>http://www.memosoup.com/20090913/grep-in-find-command-how-to-display-file-names.html#comments</comments>
		<pubDate>Sat, 12 Sep 2009 22:09:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[filename]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=73</guid>
		<description><![CDATA[<p>Here is very simple trick to force the grep command to display file name, when it&#8217;s used together with find operation.
Just write /dev/null as the &#8220;second file&#8221;</p>
<p>find . -type f -exec grep somestring {} [...]]]></description>
			<content:encoded><![CDATA[<p>Here is very simple trick to force the grep command to display file name, when it&#8217;s used together with <strong>find</strong> operation.<br />
Just write <strong>/dev/null</strong> as the &#8220;second file&#8221;</p>
<p>find . -type f -exec grep <em>somestring</em> {} <strong>/dev/null</strong> \;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090913/grep-in-find-command-how-to-display-file-names.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using pattern lists in Unix</title>
		<link>http://www.memosoup.com/20090912/using-pattern-lists-in-unix.html</link>
		<comments>http://www.memosoup.com/20090912/using-pattern-lists-in-unix.html#comments</comments>
		<pubDate>Sat, 12 Sep 2009 18:57:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[case]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=71</guid>
		<description><![CDATA[<p>Here is the small reminder about the syntax of the &#8220;case&#8221; command and the usage of the pattern lists.</p>
#!/bin/ksh
print -n &#34;Please enter the line: &#34;
read line

case &#34;$line&#34; in
&#160;?&#40;dog&#124;cat&#41; &#160;&#41; print &#34;zero or one occurrence of any pattern&#34; ;;
&#160;*&#40;low&#124;high&#41; &#41; print &#34;zero or more occurrences of any pattern&#34; ;;
&#160;@&#40;duncan&#124;methos&#41; &#41; print &#34;exactly one occurrence of any pattern&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the small reminder about the syntax of the &#8220;case&#8221; command and the usage of the pattern lists.</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 />
print <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Please enter the line: &quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">read</span> line<br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$line</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp;?<span style="color: #7a0874; font-weight: bold;">&#40;</span>dog<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">cat</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp;<span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;zero or one occurrence of any pattern&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>low<span style="color: #000000; font-weight: bold;">|</span>high<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;zero or more occurrences of any pattern&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>duncan<span style="color: #000000; font-weight: bold;">|</span>methos<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;exactly one occurrence of any pattern&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;+<span style="color: #7a0874; font-weight: bold;">&#40;</span>rudolph<span style="color: #000000; font-weight: bold;">|</span>blitzen<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;one or more occurrence of any pattern&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>grinch<span style="color: #000000; font-weight: bold;">|</span>babay<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;everything except patterns&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;-<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>hH?<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp;print <span style="color: #ff0000;">&quot;Some help...&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;-v<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>erbose<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;Some more words...&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp;<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> print <span style="color: #ff0000;">&quot;Something else...&quot;</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090912/using-pattern-lists-in-unix.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>Parsing script parameters</title>
		<link>http://www.memosoup.com/20090912/parsing-script-parameters.html</link>
		<comments>http://www.memosoup.com/20090912/parsing-script-parameters.html#comments</comments>
		<pubDate>Sat, 12 Sep 2009 15:26:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.memosoup.com/?p=44</guid>
		<description><![CDATA[<p>Quick and dirty parsing procedure for unix shell scripts</p>
parse_command_line &#40;&#41;
&#123;
typeset -i user_opt help_opt password_opt verbose_opt
typeset errmsg

arg_cou=$#

while &#91; &#34;$#&#34; -gt 0 &#93;
do
&#60;strong&#62;case &#34;$1&#34; in&#60;/strong&#62;
-@&#40;&#91;U&#93;&#41; &#41; &#160;let user_opt=user_opt+1 ;;
-P &#160; &#160; &#160; &#41; &#160; &#160;let password_opt=password_opt+1 ; ask_pass=0 ;;
-option1 &#160; &#160;&#41; &#160; &#160;;;
-option2 &#160; &#160;&#41; &#160; &#160;;;
-option3 &#160; &#160;&#41; &#160; &#160;;;
-@&#40;&#91;hH?&#93;&#41;&#41; help_opt=1;;
-v*&#40;erbose&#41;&#41; let verbose_opt=verbose_opt+1 ;;
*&#41;
if &#160; &#91; user_opt [...]]]></description>
			<content:encoded><![CDATA[<p>Quick and dirty <strong>parsing</strong> procedure for unix <strong>shell scripts</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">parse_command_line <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
<span style="color: #7a0874; font-weight: bold;">typeset</span> <span style="color: #660033;">-i</span> user_opt help_opt password_opt verbose_opt<br />
<span style="color: #7a0874; font-weight: bold;">typeset</span> errmsg<br />
<br />
<span style="color: #007800;">arg_cou</span>=<span style="color: #007800;">$#</span><br />
<br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$#&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
<span style="color: #000000; font-weight: bold;">&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span><span style="color: #000000; font-weight: bold;">&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span><br />
-<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>U<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp;<span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">user_opt</span>=user_opt+<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #660033;">-P</span> &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">password_opt</span>=password_opt+<span style="color: #000000;">1</span> ; <span style="color: #007800;">ask_pass</span>=<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #660033;">-option1</span> &nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #660033;">-option2</span> &nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #660033;">-option3</span> &nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">&#41;</span> &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">;;</span><br />
-<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>hH?<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">help_opt</span>=<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">;;</span><br />
-v<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>erbose<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">verbose_opt</span>=verbose_opt+<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">if</span> &nbsp; <span style="color: #7a0874; font-weight: bold;">&#91;</span> user_opt <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">USER</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #007800;">user_opt</span>=<span style="color: #000000;">0</span><br />
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> password_opt <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">PASS</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #007800;">password_opt</span>=<span style="color: #000000;">0</span><br />
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> verbose_opt <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;<span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">verbose_level</span>=<span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #007800;">verbose_opt</span>=<span style="color: #000000;">0</span><br />
<span style="color: #000000; font-weight: bold;">else</span><br />
<span style="color: #666666; font-style: italic;">### help_opt=1</span><br />
<span style="color: #007800;">CMD</span>=<span style="color: #007800;">$*</span> ; <span style="color: #7a0874; font-weight: bold;">break</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
<span style="color: #7a0874; font-weight: bold;">shift</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> arg_cou <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">help_opt</span>=<span style="color: #000000;">1</span> ; <span style="color: #007800;">errmsg</span>=<span style="color: #ff0000;">&quot;Nothing to do&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">for</span> opt <span style="color: #000000; font-weight: bold;">in</span> user password ; <span style="color: #000000; font-weight: bold;">do</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${opt}</span>_opt <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">help_opt</span>=<span style="color: #000000;">1</span> ; <span style="color: #007800;">errmsg</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${errmsg}</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">${opt}</span> is absent&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> verbose_opt <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #007800;">verbose_level</span>=<span style="color: #007800;">$verbose_opt</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> help_opt <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #7a0874; font-weight: bold;">help</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$errmsg</span>&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memosoup.com/20090912/parsing-script-parameters.html/feed</wfw:commentRss>
		<slash:comments>0</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>
