From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <56a297000909170716q6f2fe75dqf2abfbf89cb20265@mail.gmail.com> References: <56a297000909170716q6f2fe75dqf2abfbf89cb20265@mail.gmail.com> Date: Thu, 17 Sep 2009 15:45:27 +0100 Message-ID: From: roger peppe To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Subject: Re: [9fans] awk help; not plan9 matter Topicbox-Message-UUID: 70a2ea6a-ead5-11e9-9d60-3106f5b1d025 another approach, build up a regexp and use that: fn changefield { n = $1 repl = $2 s=')([^ ]+)(.*)' for(i in `{seq 1 `{echo $n 1 -p | dc}}){ s='[^ ]+[ ]+'^$s } s='('^$s sed 's/'^$s^'/\1'^$repl^'\3/' } (N.B. if the replacement string might contain / or \, those characters would need quoting)