From: W. James on
Ed Morton wrote:

> marc wrote:
> > Hello,
> >
> > Is it possible to replace a particular string at a particular
> > position ?
> >
> > For example, 1 by 2 at position 3 :
> >
> > 0011223344
> > =>
> > 0021223344
> >
> > but not here (not 1 at position 3)
> > 0001223344
> > =>
> > 0001223344
> >
> > I can replace any string at a position with sed : (.\{3\}\) but I
> > don't know how to test a string at the same time...
> >
> > Thanks in advance.
> >
>
> Is this what you mean?
>
> awk 'BEGIN{FS=OFS=""} {$3 = ($3==1 ? 2 : $3) }1'

No.

awk 'BEGIN{FS=OFS=""} $3==1 {$3=2} 8'

From: Geoff Clare on
Ed Morton wrote:

> awk 'BEGIN{FS=OFS=""} {$3 = ($3==1 ? 2 : $3) }1'

Beware of FS="" (or -F ""). Different versions of awk behave
differently:

$ echo abc | mawk -F "" '{ print NF }'
3
$ echo abc | gawk -F "" '{ print NF }'
1

(POSIX says the behaviour is unspecified.)

--
Geoff Clare <netnews(a)gclare.org.uk>