From: marc on 26 Nov 2009 12:15 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.
From: Ben Bacarisse on 26 Nov 2009 12:25 marc <marc.tessis(a)caramail.com> writes: > 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... Just include it in the pattern: sed -e 's/^\(.\{2\}\)1/\12/' -- Ben.
From: marc on 26 Nov 2009 12:39 On 26 nov, 18:25, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: > Just include it in the pattern: > > sed -e 's/^\(.\{2\}\)1/\12/' Ah, yes, I missed it. Many thanks !
From: Ed Morton on 26 Nov 2009 12:51 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' Regards, Ed.
From: Rakesh Sharma on 27 Nov 2009 09:41 On Nov 26, 10:15 pm, marc <marc.tes...(a)caramail.com> 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. sed -e' s/^.\{3\}/&\ / s/1\n/2/;t s/\n// ' yourfile
|
Next
|
Last
Pages: 1 2 Prev: Replace first field with the file name Next: To swap the application to firefox |