<?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>: ) wonderful world ( :</title>
	<atom:link href="http://grault.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://grault.wordpress.com</link>
	<description>the metasyntactic variable</description>
	<lastBuildDate>Sat, 14 Nov 2009 14:27:39 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='grault.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/468766593f807295f579db9ac8e2a290?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>: ) wonderful world ( :</title>
		<link>http://grault.wordpress.com</link>
	</image>
			<item>
		<title>join variable length multiline data entries with sed</title>
		<link>http://grault.wordpress.com/2009/11/13/join-variable-length-multiline-data-entries-with-sed/</link>
		<comments>http://grault.wordpress.com/2009/11/13/join-variable-length-multiline-data-entries-with-sed/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 15:19:26 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=496</guid>
		<description><![CDATA[
% cat test.txt
data1-1
data1-2
data1-3
closing-form
data2-1
data2-2
data2-3
data2-4
closing-form
data3-1
data3-2
closing-form
% cat test.txt &#124; sed -n -e ':x;N;/\nclosing-form$/!bx;s/\n/;/g;p'
data1-1;data1-2;data1-3;closing-form
data2-1;data2-2;data2-3;data2-4;closing-form
data3-1;data3-2;closing-form
%

&#160;
A precodition is that there&#8217;s no empty data entry. If there is, you can introduce helper entries:

% cat testt.txt
data1-1
data1-2
closing-form
closing-form
closing-form
data3-1
data3-2
closing-form
% cat testt.txt &#124; sed '/^closing-form$/ihelper-entry'
data1-1
data1-2
helper-entry
closing-form
helper-entry
closing-form
helper-entry
closing-form
data3-1
data3-2
helper-entry
closing-form
%

       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=496&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><pre>
% cat test.txt
data1-1
data1-2
data1-3
closing-form
data2-1
data2-2
data2-3
data2-4
closing-form
data3-1
data3-2
closing-form
% cat test.txt | sed -n -e ':x;N;/\nclosing-form$/!bx;s/\n/;/g;p'
data1-1;data1-2;data1-3;closing-form
data2-1;data2-2;data2-3;data2-4;closing-form
data3-1;data3-2;closing-form
%
</pre>
<p>&nbsp;
<p>A precodition is that there&#8217;s no empty data entry. If there is, you can introduce helper entries:</p>
<pre>
% cat testt.txt
data1-1
data1-2
closing-form
closing-form
closing-form
data3-1
data3-2
closing-form
% cat testt.txt | sed '/^closing-form$/ihelper-entry'
data1-1
data1-2
helper-entry
closing-form
helper-entry
closing-form
helper-entry
closing-form
data3-1
data3-2
helper-entry
closing-form
%
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/496/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/496/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/496/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=496&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/11/13/join-variable-length-multiline-data-entries-with-sed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>testing, states, comparison</title>
		<link>http://grault.wordpress.com/2009/11/11/testing-states-comparison/</link>
		<comments>http://grault.wordpress.com/2009/11/11/testing-states-comparison/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 14:54:49 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[feature request]]></category>
		<category><![CDATA[hard time]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=489</guid>
		<description><![CDATA[Repeatable test means that you can build up the _same_ starting state and run the _same_ test cases with the _same_ test tools configured the _same_ way. Even if you have random simulations, you should be able to reset the random seed. 
It can happen that you cannot use the same starting state in your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=489&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Repeatable test means that you can build up the _same_ starting state and run the _same_ test cases with the _same_ test tools configured the _same_ way. Even if you have random simulations, you should be able to reset the random seed. </p>
<p>It can happen that you cannot use the same starting state in your project, because it is around a terabyte (a database containing transactions and their history). You can&#8217;t step twice into the same database : ) Some sort of justification can be that this big state is an aggregate state. So a given test case depends only on its close environment. In this case though, the locality of these environments should be documented.</p>
<p>It can happen that the schema of the database changes and because of this, some of the numerous test cases are modified during the regression tests. But not all the ones that depend on the old schema (or on the schema in general). Years later nobody knows what the hell is going on when testing with those old cases. Either about the way they should be fixed.</p>
<p>By the way, don&#8217;t represent the cases in MS Access databases. In case you want to understand the evolution of a test case (e.g. along with the evolution of the database schema) by looking through the versioned history of their representation, that&#8217;s quite time consuming because there aren&#8217;t any good tools to diff MS Access databases.</p>
<p>I&#8217;m not sure though, that teaching people comparable textual representations worth it in contrast to not comparable wysiwyg editor based information forms. A solution can be a wysiwyg solution with predictable and _not_ verbose export functionality. For example <a href="http://www.postgresql.org/docs/7.4/static/app-pgdump.html">pg_dump</a> and <a href="http://www.pgadmin.org/images/screenshots/pgadmin3_win32.png">pgadmin</a> as GUI:</p>
<pre>
% pg_dump -s | grep -v ^-- &gt; dbscm1.sql
% psql -q
=&gt; create table zfoo (a serial primary key, c numeric check (c &gt; 0));
NOTICE:  CREATE TABLE will create implicit sequence "zfoo_a_seq" for "serial" column "zfoo.a"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "zfoo_pkey" for table "zfoo"
=&gt; \q
% pg_dump -s | grep -v ^-- &gt; dbscm2.sql
% diff dbscm1.sql dbscm2.sql
270a271,278
&gt; CREATE TABLE zfoo (
&gt;     a serial NOT NULL,
&gt;     c numeric,
&gt;     CONSTRAINT zfoo_c CHECK ((c &gt; (0)::numeric))
&gt; );
&gt;
&gt;
&gt;
340a349,353
&gt; ALTER TABLE ONLY zfoo
&gt;     ADD CONSTRAINT zfoo_pkey PRIMARY KEY (a);
&gt;
&gt;
&gt;
%
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/489/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/489/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/489/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=489&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/11/11/testing-states-comparison/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>graph algorithms with GraphViz and agraph</title>
		<link>http://grault.wordpress.com/2009/11/10/graph-algorithms-with-graphviz-and-agraph/</link>
		<comments>http://grault.wordpress.com/2009/11/10/graph-algorithms-with-graphviz-and-agraph/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 15:10:21 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[windowns]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=483</guid>
		<description><![CDATA[
% find
.
./bin
./bin/cdt.dll
./bin/graph.dll
./bin/sample.gv
./incomings.c
./Makefile

%

&#160;

These are the files from this hello world project. The dlls are from the GraphViz installation directory (from bin/). The task is to collect incoming nodes for a given other node (the ones that have directed edges into the selected one). The good thing in this is that you don&#8217;t have to design you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=483&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><pre>
% find
.
./bin
./bin/cdt.dll
./bin/graph.dll
./bin/sample.gv
./incomings.c
./Makefile

%
</pre>
<p>&nbsp;
<p>
These are the files from this hello world project. The dlls are from the GraphViz installation directory (from bin/). The task is to collect incoming nodes for a given other node (the ones that have directed edges into the selected one). The good thing in this is that you don&#8217;t have to design you own graph markup language and your own parser (<a href="http://en.wikipedia.org/wiki/Not_Invented_Here">NIH</a>). Instead you can use the well defined and supported <a href="http://graphviz.org/doc/info/lang.html">dot language</a> from <a>GraphViz</a>. I&#8217;ve used MingW and MSYS as development environment.</p>
<pre>
% cat -A Makefile
all:^Iincomings.exe$
$
incomings.exe:^Iincomings.o$
^Ig++ $&lt; -O2 -o bin/$@ `PKG_CONFIG_PATH=c:/Graphviz2.24/lib/pkgconfig/ pkg-confi
g --libs libgvc`$
$
incomings.o:^Iincomings.c$
^Ig++ $&lt; -O2 -c -o $@ `PKG_CONFIG_PATH=c:/Graphviz2.24/lib/pkgconfig/ pkg-config
 --cflags libgvc`$
$
clean:$
^Irm -rf incomings.o bin/incomings.exe$
$
test:^Iall$
^Ibin/incomings.exe bin/sample.gv a$

% cat incomings.c
#include&lt;gvc.h&gt;

char* gv_gets(char *buf, int n, FILE* fp)
{
  return fgets(buf,n,fp);
}

int main (int argc, char **argv)
{
  Agraph_t *g;
  Agnode_t *n;
  Agedge_t *e;
  FILE *fp;

  if(argc &gt; 2)
    fp=fopen(argv[1],"r");
  else
    fp=stdin;

  aginit();
  g=agread_usergets(fp,gv_gets);
  for(n=agfstnode(g);n;n=agnxtnode(g,n))
    if(strcmp(n-&gt;name,argv[argc-1])==0)
      for(e=agfstin(g,n);e;e=agnxtin(g,e))
        printf("%s\n",e-&gt;tail-&gt;name);

  agclose(g);
  return 0;
}

% make
g++ incomings.c -O2 -c -o incomings.o `PKG_CONFIG_PATH=c:/Graphviz2.24/lib/pkgco
nfig/ pkg-config --cflags libgvc`
g++ incomings.o -O2 -o bin/incomings.exe `PKG_CONFIG_PATH=c:/Graphviz2.24/lib/pk
gconfig/ pkg-config --libs libgvc`

% cat bin/sample.gv
digraph G
{
  b -&gt; a;
  c -&gt; a;
  d -&gt; a;
  e -&gt; a;
  f -&gt; a;
  a -&gt; foo;
}

% make test
g++ incomings.o -O2 -o bin/incomings.exe `PKG_CONFIG_PATH=c:/Graphviz2.24/lib/pk
gconfig/ pkg-config --libs libgvc`
bin/incomings.exe bin/sample.gv a
b
c
d
e
f

%
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/483/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/483/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/483/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=483&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/11/10/graph-algorithms-with-graphviz-and-agraph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>granting a loan; simplified</title>
		<link>http://grault.wordpress.com/2009/11/08/granting-a-loan-simplified/</link>
		<comments>http://grault.wordpress.com/2009/11/08/granting-a-loan-simplified/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 12:36:25 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=477</guid>
		<description><![CDATA[Based on the net present value term, in case of regular $R incomes and rate as discount rate:

      years - 1
      ---------
      \
       \        R
NPV =  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=477&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Based on the <a href="http://en.wikipedia.org/wiki/Net_present_value">net present value</a> term, in case of regular $R incomes and rate as discount rate:</p>
<pre>
      years - 1
      ---------
      \
       \        R
NPV =   )       -------------
       /                    i
      /         /          \
      --------- | 1 + rate |
        i = 0   \          /
</pre>
<p>&nbsp;
<p>
Due to identical cash flows this is the sum of a <a href="http://en.wikipedia.org/wiki/Geometric_series">geometric series</a>, so can be rewritten into a closed form:</p>
<pre>
                        years
            /          \
            | 1        |
        1 - | -------- |
            | 1 + rate |
            \          /
NPV = R ---------------------
            1
        1 - --------
            1 + rate
</pre>
<p>&nbsp;
<p>
Or identically:</p>
<pre>
            1
        1 - --------
            1 + rate
R = NPV ---------------------
                        years
            /          \
            | 1        |
        1 - | -------- |
            | 1 + rate |
            \          /
</pre>
<p>&nbsp;
<p>
In case duration of the loan tends to infinity then the required yearly income converges to:</p>
<pre>
    /              \
    |     1        |
NPV | 1 - -------- |
    |     1 + rate |
    \              /
</pre>
<p>&nbsp;
<p>
which is</p>
<pre>
    rate
NPV --------
    1 + rate
</pre>
<p>&nbsp;
<p>
and this means that there&#8217;s no loan of USD NPV regarding rate as discount rate, where the required yearly pay back is less then this number, e.g. (NPV = $1000000, rate = 0.03):</p>
<pre>
% ./lx86cl
Welcome to Clozure Common Lisp Version 1.4-r13119  (LinuxX8632)!
? (defun limit (npv rate) (* npv (/ rate (+ 1 rate))))
LIMIT
? (limit 1000000 0.03)
29126.213
? (defun r (npv rate years)
(* npv (/ (- 1 (/ 1 (+ 1 rate))) (- 1 (expt (/ 1 (+ 1 rate)) years)))))
R
? (loop as i from 1 upto 50 collect (r 1000000 0.03 i))
(1000000.0 507389.3 343233.47 261191.42 211994.77 179220.95 155831.47 138307.22 124693.086
113816.05 104929.58 97536.03 91290.83 85947.914 81326.79 77292.09 73740.32 70590.97 67780.47
65257.973 62982.297 60919.8 59042.617 57327.58 55755.207 54309.016 52974.95 51740.992 50596.758
49533.246 48542.637 47618.066 46753.5 45943.64 45183.758 44469.687 43797.676 43164.387 42566.824
42002.29 41468.336 40962.766 40483.58 40028.957 39597.234 39186.906 38796.586 38425.0 38070.984
37733.465)
? (with-open-file (s #P"r.dat" :direction :output :if-exists :supersede)
(loop as val in * do (format s "~A~%" val)))
NIL
? (quit)
% echo set term png \; plot \'r.dat\' with lines | gnuplot &gt; r.png
</pre>
<div id="attachment_479" class="wp-caption aligncenter" style="width: 650px"><a href="http://grault.files.wordpress.com/2009/11/r.png"><img src="http://grault.files.wordpress.com/2009/11/r.png?w=640&#038;h=480" alt="r" title="r" width="640" height="480" class="size-full wp-image-479" /></a><p class="wp-caption-text">r.png</p></div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/477/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/477/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/477/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=477&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/11/08/granting-a-loan-simplified/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>

		<media:content url="http://grault.files.wordpress.com/2009/11/r.png" medium="image">
			<media:title type="html">r</media:title>
		</media:content>
	</item>
		<item>
		<title>rebuild cffi foreign bindings</title>
		<link>http://grault.wordpress.com/2009/11/03/rebuild-cffi-foreign-bindings/</link>
		<comments>http://grault.wordpress.com/2009/11/03/rebuild-cffi-foreign-bindings/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 12:29:08 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[lisp]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[windowns]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=472</guid>
		<description><![CDATA[
C:\grault&#62;type lib-foo.c
int getone ()
{
   return 1;
}

C:\grault&#62;gcc -shared -o lib-foo.dll lib-foo.c

C:\grault&#62;clisp -q -norc -i ..\.clisprc
;; Loading file ..\.clisprc ...
[1]&#62; (setf *load-verbose* nil)
NIL
[2]&#62; (asdf:oos 'asdf:load-op :cffi :verbose nil)
#&#60;ASDF:LOAD-OP (:VERBOSE NIL) #x19C29B55&#62;
[3]&#62; (cffi:load-foreign-library "lib-foo")
#&#60;CFFI::FOREIGN-LIBRARY #x19CCE065&#62;
[4]&#62; (cffi:defcfun  "getone" :int)
GETONE
[5]&#62; (getone)
1
[6]&#62; (ext:saveinitmem "foo.mem" :norc t)

Bytes permanently allocated:           [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=472&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><pre>
C:\grault&gt;type lib-foo.c
int getone ()
{
   return 1;
}

C:\grault&gt;gcc -shared -o lib-foo.dll lib-foo.c

C:\grault&gt;clisp -q -norc -i ..\.clisprc
;; Loading file ..\.clisprc ...
[1]&gt; (setf *load-verbose* nil)
NIL
[2]&gt; (asdf:oos 'asdf:load-op :cffi :verbose nil)
#&lt;ASDF:LOAD-OP (:VERBOSE NIL) #x19C29B55&gt;
[3]&gt; (cffi:load-foreign-library "lib-foo")
#&lt;CFFI::FOREIGN-LIBRARY #x19CCE065&gt;
[4]&gt; (cffi:defcfun  "getone" :int)
GETONE
[5]&gt; (getone)
1
[6]&gt; (ext:saveinitmem "foo.mem" :norc t)

Bytes permanently allocated:             92,512
Bytes currently in use:               3,409,664
Bytes available until next GC:          852,166
3409664 ;
852166 ;
92512 ;
38 ;
20303572 ;
2808018
[7]&gt; (quit)

C:\grault&gt;dir/b
foo.mem
lib-foo.c
lib-foo.dll

C:\grault&gt;clisp -q -M foo.mem
[1]&gt; (getone)
WARNING: FFI::FIND-FOREIGN-FUNCTION: no dynamic object named "getone" in library :DEFAULT
*** - FUNCALL: undefined function NIL
The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead of (FDEFINITION 'NIL).
RETRY          :R2      Retry
STORE-VALUE    :R3      Input a new value for (FDEFINITION 'NIL).
ABORT          :R4      Abort main loop
Break 1 [2]&gt; :r4
[3]&gt; (cffi:use-foreign-library "lib-foo")
#&lt;CFFI::FOREIGN-LIBRARY #x19FB66AD&gt;
[4]&gt; (getone)
1
[5]&gt; (quit)

C:\grault&gt;
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/472/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=472&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/11/03/rebuild-cffi-foreign-bindings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>common lisp GUI-application shipment&amp;delivery on windows</title>
		<link>http://grault.wordpress.com/2009/10/30/common-lisp-gui-application-shipment-delivery-on-windows/</link>
		<comments>http://grault.wordpress.com/2009/10/30/common-lisp-gui-application-shipment-delivery-on-windows/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:38:10 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[feature request]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[windowns]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=460</guid>
		<description><![CDATA[First of all, here&#8217;s the lisp I&#8217;ve used:

% clisp --version &#124; grep -v ^Machine
GNU CLISP 2.48 (2009-07-28) (built on stnt067 [192.168.0.1])
Software: GNU C 3.4.5 (mingw-vista special r3)
gcc -mno-cygwin -O2 -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-ty
pe -Wmissing-declarations -Wno-sign-compare -Wno-format-nonliteral -O2 -fexpensi
ve-optimizations -falign-functions=4 -D_WIN32 -DUNICODE -DDYNAMIC_FFI -I.  -lint
l -lreadline -ltermcap -lavcall -lcallback -luser32 -lws2_32 -lole32 -loleaut32
-luuid [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=460&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>First of all, here&#8217;s the lisp I&#8217;ve used:</p>
<pre>
% clisp --version | grep -v ^Machine
GNU CLISP 2.48 (2009-07-28) (built on stnt067 [192.168.0.1])
Software: GNU C 3.4.5 (mingw-vista special r3)
gcc -mno-cygwin -O2 -W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-ty
pe -Wmissing-declarations -Wno-sign-compare -Wno-format-nonliteral -O2 -fexpensi
ve-optimizations -falign-functions=4 -D_WIN32 -DUNICODE -DDYNAMIC_FFI -I.  -lint
l -lreadline -ltermcap -lavcall -lcallback -luser32 -lws2_32 -lole32 -loleaut32
-luuid -liconv -lsigsegv
SAFETY=0 HEAPCODES STANDARD_HEAPCODES GENERATIONAL_GC SPVW_BLOCKS SPVW_MIXED TRI
VIALMAP_MEMORY
libsigsegv 2.6
libiconv 1.11
libreadline 5.2
Features:
(READLINE REGEXP SYSCALLS I18N LOOP COMPILER CLOS MOP CLISP ANSI-CL COMMON-LISP
LISP=CL INTERPRETER SOCKETS GENERIC-STREAMS
 LOGICAL-PATHNAMES SCREEN FFI GETTEXT UNICODE BASE-CHAR=CHARACTER PC386 WIN32)
C Modules: (clisp i18n syscalls regexp readline)
Installation directory: C:\Program Files\clisp-2.48\
User language: ENGLISH

%
</pre>
<p>&nbsp;
<p>
I have also MingW (5.1.6) and MSYS (1.0.1) installed, <a href="http://www.iconarchive.com/category/halloween/spooktacular-halloween-icons-by-leoyue.html">Witchs Hat icon</a> downloaded, <a href="http://clisp.cons.org">CLisp</a> dlls copied from the base subdirectory under the installation path. This is the development tree in clean form:</p>
<pre>
% find
.
./bootstrapper.cc
./bootstrapper.rc
./clisp-dlls
./clisp-dlls/libiconv-2.dll
./clisp-dlls/libintl-8.dll
./clisp-dlls/readline5.dll
./Makefile
./message.lisp
./witchs-hat.ico
%
</pre>
<p>&nbsp;
<p>
Under clisp-dlls, there are the mentioned dlls of CLisp. The file message.lisp contains the program you&#8217;d like to run (or ship or whatever). Finally, the bootstrapper files are up to provide an exe with company info, icon, copyright, etc. as an entry to the lisp program. The important bit here is that you don&#8217;t want a command prompt window popping up before startup.<br />
Let&#8217;s see the files:</p>
<pre>
% <b>cat message.lisp</b>
(use-package "FFI")
(def-call-out messagebox
  (:name "MessageBoxA") (:library "user32.dll")
  (:arguments (hwnd int) (text c-string) (capt c-string) (type uint))
  (:return-type int)
  (:language :stdc))

(defun main ()
  (messagebox 0 "Your hacking starts... NOW!" "Demo MsgBox" 0)
  (quit))
% <b>cat -A Makefile</b>
all:^Imsgbox-app.exe msgbox-app.img$
^Imkdir -p shipment$
^Icp msgbox-app.exe shipment$
^Icp msgbox-app.img shipment$
^Icp clisp-dlls/* shipment$
$
msgbox-app.img:^Imsgbox-app.img.exe$
^Icp $&lt; $@$
$
msgbox-app.img.exe:^Imessage.lisp$
^Iclisp -q -norc -x \$
&quot;(load \&quot;message.lisp\&quot;) \$
(ext:saveinitmem #P\&quot;./msgbox-app.img.exe\&quot; \$
                 :executable t \$
                 :norc t \$
                 :init-function #&#39;main)&quot;$
$
bootstrapper.res:^Ibootstrapper.rc witchs-hat.ico$
^Iwindres $&lt; -O coff -o $@$
^I$
msgbox-app.exe:^Ibootstrapper.cc bootstrapper.res$
^Ig++ -mwindows $^ -o $@$
$
clean:$
^Irm -rf msgbox-app.exe bootstrapper.res \$
^Imsgbox-app.img msgbox-app.img.exe shipment$
% <b>cat bootstrapper.rc</b>
ID ICON "witchs-hat.ico"
1 VERSIONINFO
FILEVERSION     1,0,0,0
PRODUCTVERSION  1,0,0,0
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "080904E4"
    BEGIN
      VALUE "CompanyName", "MsgBox Products"
      VALUE "FileDescription", "Demo MsgBox"
      VALUE "FileVersion", "1.0"
      VALUE "InternalName", "msgbox-app"
      VALUE "LegalCopyright", "Grault"
      VALUE "OriginalFilename", "msgbox-app.exe"
      VALUE "ProductName", "Demo MsgBox"
      VALUE "ProductVersion", "1.0"
    END
  END

  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x809, 1252
  END
END
% <b>cat bootstrapper.cc</b>
#include &lt;windows.h&gt;

int WinMain(HINSTANCE a0, HINSTANCE a1, LPSTR a2, int a3)
{
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  ZeroMemory(&amp;si,sizeof(STARTUPINFO));
  si.cb = sizeof(STARTUPINFO);
  CreateProcess("msgbox-app.img", "",
     NULL,NULL,TRUE,<i>CREATE_NO_WINDOW</i>,NULL,
     NULL,&amp;si,&amp;pi);
  // version and company details are in the bootstrapper exe
  // it's kinda better to show these e.g. in process explorer
  // and image file as a subprocess
  // feel free to comment the following line to leave img only
  WaitForSingleObject(pi.hProcess, INFINITE);
  return 0;
}
%
</pre>
<p>&nbsp;
<p>These are the files, and here are the results of a make:</p>
<pre>
% make
windres bootstrapper.rc -O coff -o bootstrapper.res
g++ -mwindows bootstrapper.cc bootstrapper.res -o msgbox-app.exe
clisp -q -norc -x \
"(load \"message.lisp\") \
(ext:saveinitmem #P\"./msgbox-app.img.exe\" \
                 :executable t \
                 :norc t \
                 :init-function #'main)"
;; Loading file message.lisp ...
;; Loaded file message.lisp
T
;; Wrote the memory image into .\msgbox-app.img.exe (5,088,157 bytes)
Bytes permanently allocated:             92,512
Bytes currently in use:               2,188,704
Bytes available until next GC:          544,546
2188704 ;
544546 ;
92512 ;
1 ;
52160 ;
156001
cp msgbox-app.img.exe msgbox-app.img
mkdir -p shipment
cp msgbox-app.exe shipment
cp msgbox-app.img shipment
cp clisp-dlls/* shipment
% find
.
./bootstrapper.cc
./bootstrapper.rc
./bootstrapper.res
./clisp-dlls
./clisp-dlls/libiconv-2.dll
./clisp-dlls/libintl-8.dll
./clisp-dlls/readline5.dll
./Makefile
./message.lisp
./msgbox-app.exe
./msgbox-app.img
./msgbox-app.img.exe
./shipment
./shipment/libiconv-2.dll
./shipment/libintl-8.dll
./shipment/msgbox-app.exe
./shipment/msgbox-app.img
./shipment/readline5.dll
./witchs-hat.ico
</pre>
<p>&nbsp;</p>
<p>Here&#8217;s a picture how this all looks like on a Windows Server 2003 Standard Edition without any kind of lisp installed. And the entries in Process Explorer.<br />
<div id="attachment_463" class="wp-caption aligncenter" style="width: 666px"><a href="http://grault.files.wordpress.com/2009/10/shipped1.png"><img src="http://grault.files.wordpress.com/2009/10/shipped1.png?w=656&#038;h=516" alt="shipped" title="shipped" width="656" height="516" class="size-full wp-image-463" /></a><p class="wp-caption-text">Some sort of shipment : )</p></div><br />
<div id="attachment_465" class="wp-caption aligncenter" style="width: 710px"><a href="http://grault.files.wordpress.com/2009/10/shipped-pe.jpg"><img src="http://grault.files.wordpress.com/2009/10/shipped-pe.jpg?w=700&#038;h=46" alt="shipped-pe" title="shipped-pe" width="700" height="46" class="size-full wp-image-465" /></a><p class="wp-caption-text">show up in Process Explorer</p></div></p>
<p>Obviously one can develop a much more sophisticated bootstrapper. This one represents only the possibility of releasing software written in Lisp. Assembling these output files together into an installer could be the next step : ))</p>
<p>&nbsp;</p>
<p>And finally, you can get either the binaries or the source files by sending a mail to:</p>
<pre>
% echo gra.rtebsrpehbf.ferfh@gyhnet | rev | tr '[a-z]' '[n-za-m]'
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/460/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/460/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/460/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=460&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/10/30/common-lisp-gui-application-shipment-delivery-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>

		<media:content url="http://grault.files.wordpress.com/2009/10/shipped1.png" medium="image">
			<media:title type="html">shipped</media:title>
		</media:content>

		<media:content url="http://grault.files.wordpress.com/2009/10/shipped-pe.jpg" medium="image">
			<media:title type="html">shipped-pe</media:title>
		</media:content>
	</item>
		<item>
		<title>7zip loads of files in a single folder</title>
		<link>http://grault.wordpress.com/2009/10/22/7zip-loads-of-files-in-a-single-folder/</link>
		<comments>http://grault.wordpress.com/2009/10/22/7zip-loads-of-files-in-a-single-folder/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 12:37:03 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[windowns]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=454</guid>
		<description><![CDATA[I&#8217;ve met with a folder with around 400000 files on Windows. Listing the files takes more than 5 minutes for an explorer window which is infinity in IT terms : ) Setting the working directory to this one in a cmd window works. Great. Starting a dir command in cmd leads to this infinity of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=454&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve met with a folder with around 400000 files on Windows. Listing the files takes more than 5 minutes for an explorer window which is infinity in IT terms : ) Setting the working directory to this one in a cmd window works. Great. Starting a dir command in cmd leads to this infinity of silence also. Suprisingly if your file names are structured enough to hash them with a prefix, then `dir prefix1*&#8217; is relatively fast. Therefore creating directories for the values and moving the groups to these solves the problem somewhat. I also decided to zip these folders of grouped files (by a hash on their names). 7z run time somehow depends on the nr of files in current directory even if you&#8217;re up to compress the files in a single subdirectory into a file which is in the current working one. This can be an issue when you have hundreds of thousands files in a single directory. So it&#8217;s better to separate the files first and compress them after.</p>
<p>Here&#8217;s the batch file I&#8217;ve used to solve this.</p>
<pre>
set list=^
200801 200802 200803 200804 200805 200806 ^
200807 200808 200809 200810 200811 200812 ^
200901 200902 200903 200904 200905 200906 ^
200907 200908 200909

for %%i in (%list%) do (
md archive_%%i
move someprefix%%i* archive_%%i\
)

for %%i in (%list%) do (
7z a archive_%%i.7z archive_%%i\
)
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/454/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/454/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/454/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=454&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/10/22/7zip-loads-of-files-in-a-single-folder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>manipulate k-th column in file with sed &amp; friends</title>
		<link>http://grault.wordpress.com/2009/10/15/manipulate-k-th-column-in-file-with-sed-friends/</link>
		<comments>http://grault.wordpress.com/2009/10/15/manipulate-k-th-column-in-file-with-sed-friends/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 14:48:53 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[feature request]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=451</guid>
		<description><![CDATA[
$ echo $0
bash
$

&#160;

Which means that all the stuff below holds at least when using Bash. One of the important features in it is &#8220;Process Substitution&#8221;. Not so efficient (due to extra bash processes spawned), but I just don&#8217;t care at the moment..
The first use case is to manipulate the k-th column of a file. Let&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=451&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><pre>
$ echo $0
bash
$
</pre>
<p>&nbsp;
<p>
Which means that all the stuff below holds at least when using <a href="http://en.wikipedia.org/wiki/Bash">Bash</a>. One of the important features in it is &#8220;Process Substitution&#8221;. Not so efficient (due to extra bash processes spawned), but I just don&#8217;t care at the moment..</p>
<p>The first use case is to manipulate the k-th column of a file. Let&#8217;s see our test file:</p>
<pre>
$ cat -A if1.txt
a^Ib^Ic^Id^Ie^If^Ig^Ih$
b^Ic^Id^Ie^If^Ig^Ih^Ia$
c^Id^Ie^If^Ig^Ih^Ia^Ib$
d^Ie^If^Ig^Ih^Ia^Ib^Ic$
e^If^Ig^Ih^Ia^Ib^Ic^Id$
f^Ig^Ih^Ia^Ib^Ic^Id^Ie$
g^Ih^Ia^Ib^Ic^Id^Ie^If$
h^Ia^Ib^Ic^Id^Ie^If^Ig$
$ cat if1.txt
a       b       c       d       e       f       g       h
b       c       d       e       f       g       h       a
c       d       e       f       g       h       a       b
d       e       f       g       h       a       b       c
e       f       g       h       a       b       c       d
f       g       h       a       b       c       d       e
g       h       a       b       c       d       e       f
h       a       b       c       d       e       f       g
$
</pre>
<p>&nbsp;
<p>The problem is to search and replace with sed, but only in a given column.<br />
The first solution is done by using paste, cut.</p>
<pre>
$ paste &lt;(cut -f-4 if1.txt) &lt;(cut -f5 if1.txt | sed 's/h/x/g') &lt;(cut -f6- if1.txt)
a       b       c       d       e       f       g       h
b       c       d       e       f       g       h       a
c       d       e       f       g       h       a       b
d       e       f       g       x       a       b       c
e       f       g       h       a       b       c       d
f       g       h       a       b       c       d       e
g       h       a       b       c       d       e       f
h       a       b       c       d       e       f       g
$
</pre>
<p>&nbsp;
<p>
The second one uses the bash language and its read command which is able to fill an array with values read from a line.</p>
<pre>
$ cat if1.txt | while read -a line; do
&gt; line[4]=$(echo ${line[4]} | sed 's/h/x/')
&gt; echo -e ${line[*]} | sed 's/\ /\t/g'
&gt; done
a       b       c       d       e       f       g       h
b       c       d       e       f       g       h       a
c       d       e       f       g       h       a       b
d       e       f       g       x       a       b       c
e       f       g       h       a       b       c       d
f       g       h       a       b       c       d       e
g       h       a       b       c       d       e       f
h       a       b       c       d       e       f       g
$
</pre>
<p>&nbsp;
<p>
Note that this multiline command can be written into a single line as well (obviously by removing the secondary prompt characters).</p>
<p>
Now what if you want to do computations based on other columns. Here&#8217;s the same approach for this (removing 2nd and 4th columns and introducing a new 3rd one which should be the sum of the two deleted ones):</p>
<pre>
$ cat -A if2.txt
a^I1^Id^I2$
b^I3^Ie^I4$
c^I5^If^I6$
$ cat if2.txt
a       1       d       2
b       3       e       4
c       5       f       6
$ paste &lt;(cut -f1,3 if2.txt) &lt;(cut -f2,4 if2.txt | sed 's/$/ + p/' | dc)
a       d       3
b       e       7
c       f       11
$ cat if2.txt | while read -a line; do
&gt; echo -e ${line[0]}\\t${line[2]}\\t$(echo ${line[1]} ${line[3]} + p | dc)
&gt; done
a       d       3
b       e       7
c       f       11
$
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/451/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/451/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/451/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/451/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/451/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/451/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/451/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/451/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/451/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/451/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=451&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/10/15/manipulate-k-th-column-in-file-with-sed-friends/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>moving from ucw to wui (&amp; cl-dwim)</title>
		<link>http://grault.wordpress.com/2009/09/21/moving-from-ucw-to-wui-cl-dwim/</link>
		<comments>http://grault.wordpress.com/2009/09/21/moving-from-ucw-to-wui-cl-dwim/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 09:29:15 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=442</guid>
		<description><![CDATA[As per the UCW repository the project seems to be abandoned a bit. There&#8217;s a new upcoming lisp based web development framework called cl-dwim with it&#8217;s own demo site.
WUI (a subproject of cl-dwim) has numerous asdf dependencies, so collecting the right version of these can be a bit time consuming, but AFAIK there will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=442&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As per the UCW <a href="http://common-lisp.net/cgi-bin/darcsweb/darcsweb.cgi?r=ucw-ucw_dev">repository</a> the project seems to be abandoned a bit. There&#8217;s a new upcoming lisp based web development framework called <a href="http://common-lisp.net/project/cl-dwim/">cl-dwim</a> with it&#8217;s own <a href="http://dwim.hu/">demo site</a>.</p>
<p>WUI (a subproject of cl-dwim) has numerous asdf dependencies, so collecting the right version of these can be a bit time consuming, but AFAIK there will be some kind of boxset version as for UCW. I was able to start up the server and write some sort of hello world program with it, screencast is coming soon.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/442/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/442/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/442/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=442&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/09/21/moving-from-ucw-to-wui-cl-dwim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>
	</item>
		<item>
		<title>snus in a roll</title>
		<link>http://grault.wordpress.com/2009/09/10/snus-in-a-roll/</link>
		<comments>http://grault.wordpress.com/2009/09/10/snus-in-a-roll/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 09:56:31 +0000</pubDate>
		<dc:creator>grault</dc:creator>
				<category><![CDATA[snus]]></category>
		<category><![CDATA[tobacco]]></category>

		<guid isPermaLink="false">http://grault.wordpress.com/?p=434</guid>
		<description><![CDATA[       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=434&subd=grault&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div class="wp-caption aligncenter" style="width: 385px"><a href="http://www.flickr.com/photos/xabolx-xuux/3906593512/"><img alt="wholesale" src="http://farm3.static.flickr.com/2427/3906593512_b7ea544e60.jpg" title="wholesale" width="375" height="500" /></a><p class="wp-caption-text">wholesale</p></div>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/grault.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/grault.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/grault.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/grault.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/grault.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/grault.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/grault.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/grault.wordpress.com/434/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/grault.wordpress.com/434/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/grault.wordpress.com/434/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=grault.wordpress.com&blog=1965392&post=434&subd=grault&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://grault.wordpress.com/2009/09/10/snus-in-a-roll/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/79892686fba0e62f258208d712c8e7ad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">grault</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2427/3906593512_b7ea544e60.jpg" medium="image">
			<media:title type="html">wholesale</media:title>
		</media:content>
	</item>
	</channel>
</rss>