From: W. James on 28 Nov 2009 17:01 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 30 Nov 2009 08:49 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>
First
|
Prev
|
Pages: 1 2 Prev: Replace first field with the file name Next: To swap the application to firefox |