From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <978914fc9c9bab9ce8d96dabbc39e9c4@quanstro.net> Date: Thu, 17 Sep 2009 22:33:40 +0200 Message-ID: From: Rudolf Sykora To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [9fans] awk help; not plan9 matter Topicbox-Message-UUID: 7168ca6e-ead5-11e9-9d60-3106f5b1d025 2009/9/17 roger peppe : > just change the regexp as required. Ok. I decided (although just for game now) to play a little with the idea of building the regexp. Starting from Eric's post I slowly progressed to sth. quite similar to your post :) : fn buildre { re = 's:^([ ]*)(' for(i in `{seq 1 `{hoc -e $1-1}}) re = $re ^ '[^ ]+[ ]+' re = $re ^ ')[^ ]+:\1\2' ^ $2: } This works (even takes care about leading spaces) unless I want to use it for the 1st field. Then the produced regexp (buildre 1 hell)is s:^([ ]*)()[^ ]+:\1\2hell: and sed says sed: Command garbled: s:^([ ]*)()[^ ]+:\1\2hell: Apparently it dislikes the empty group, (). Is there any reason? I tried it in linux, there with echo '1 28 3' | sed 's:^\([ ]*\)\(\)[^ ][^ ]*:\1\2hell:' and it works as expected... Thanks Ruda