|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I have a file : 775.2 89.2 96.1 234 384 441.4 AMA 8422 30 28 99 82 10.3 AMA 9.23 331 22.1 When ever the first column has a 'AMA;' I need to then pre/post a '@' at each number on that row, so I have something: 775.2 89.2 96.1 234 384 441.4 AMA @8422@ @30@ @28@ 99 82 10.3 AMA @9.23@ @331@ @22.1@ I have tried using: sed -e 's/\(^AMA [0-9*]*\)/\@/g' , but this soes not return the results I'd expect. Could someone point me in the right direction. Thanks Pete |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Fri, 01 Dec 2006 06:08:11 -0800, peter_sands@techemail.com wrote:
> Hi, > I have a file : > 775.2 89.2 96.1 > 234 384 441.4 > AMA 8422 30 28 > 99 82 10.3 > AMA 9.23 331 22.1 > > When ever the first column has a 'AMA;' I need to then pre/post a '@' > at each number on that row, > so I have something: > 775.2 89.2 96.1 > 234 384 441.4 > AMA @8422@ @30@ @28@ > 99 82 10.3 > AMA @9.23@ @331@ @22.1@ > > I have tried using: sed -e 's/\(^AMA [0-9*]*\)/\@/g' , but this soes sed '/^AMA/{s/\([[:digit:]]\+\)/@\1@/g}' Eric |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
<peter_sands@techemail.com> wrote in message news:1164982091.034593.180470@73g2000cwn.googlegro ups.com... > Hi, > I have a file : > 775.2 89.2 96.1 > 234 384 441.4 > AMA 8422 30 28 > 99 82 10.3 > AMA 9.23 331 22.1 > > When ever the first column has a 'AMA;' I need to then pre/post a '@' > at each number on that row, > so I have something: > 775.2 89.2 96.1 > 234 384 441.4 > AMA @8422@ @30@ @28@ > 99 82 10.3 > AMA @9.23@ @331@ @22.1@ [...] sed '/AMA/ s/\([0-9]\{1,\}\.*[0-9]\{0,\}\)/ @\1@ /g' infile Regards Dimitre |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
peter_sands@techemail.com wrote:
> Hi, > I have a file : > 775.2 89.2 96.1 > 234 384 441.4 > AMA 8422 30 28 > 99 82 10.3 > AMA 9.23 331 22.1 > > When ever the first column has a 'AMA;' I need to then pre/post a '@' > at each number on that row, > so I have something: > 775.2 89.2 96.1 > 234 384 441.4 > AMA @8422@ @30@ @28@ > 99 82 10.3 > AMA @9.23@ @331@ @22.1@ > > I have tried using: sed -e 's/\(^AMA [0-9*]*\)/\@/g' , but this soes > not return the results I'd expect. > Could someone point me in the right direction. Select only lines that match pattern AMA for the substitution. Use \1 to reference the first \(...\) subexpression. > Thanks > Pete > sed '/^AMA/s/\([0-9.]\+\)/@\1@/g' Janis |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Radoulov, Dimitre :
> <peter_sands@techemail.com> wrote in message > news:1164982091.034593.180470@73g2000cwn.googlegro ups.com... >> Hi, >> I have a file : >> 775.2 89.2 96.1 >> 234 384 441.4 >> AMA 8422 30 28 >> 99 82 10.3 >> AMA 9.23 331 22.1 >> >> When ever the first column has a 'AMA;' I need to then pre/post a '@' >> at each number on that row, >> so I have something: >> 775.2 89.2 96.1 >> 234 384 441.4 >> AMA @8422@ @30@ @28@ >> 99 82 10.3 >> AMA @9.23@ @331@ @22.1@ > [...] > > sed '/AMA/ s/\([0-9]\{1,\}\.*[0-9]\{0,\}\)/ @\1@ /g' infile why is this @\1@? I think it should be @\0@ > > > Regards > Dimitre > > |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
peter_sands@techemail.com wrote:
> Hi, > I have a file : > 775.2 89.2 96.1 > 234 384 441.4 > AMA 8422 30 28 > 99 82 10.3 > AMA 9.23 331 22.1 > > When ever the first column has a 'AMA;' I need to then pre/post a '@' > at each number on that row, > so I have something: > 775.2 89.2 96.1 > 234 384 441.4 > AMA @8422@ @30@ @28@ > 99 82 10.3 > AMA @9.23@ @331@ @22.1@ > > I have tried using: sed -e 's/\(^AMA [0-9*]*\)/\@/g' , but this soes > not return the results I'd expect. > Could someone point me in the right direction. > Thanks > Pete > The g option will require that AMA is preceding each field. But you can use a search address: sed '/^AMA/s/[0-9][0-9.]*/\@&\@/g' -- Michael Tosch @ hp : com |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
"Radoulov, Dimitre" <cichomitiko@gmail.com> wrote in message news:45703d1d$0$49197$14726298@news.sunsite.dk... > > <peter_sands@techemail.com> wrote in message > news:1164982091.034593.180470@73g2000cwn.googlegro ups.com... >> Hi, >> I have a file : >> 775.2 89.2 96.1 >> 234 384 441.4 >> AMA 8422 30 28 >> 99 82 10.3 >> AMA 9.23 331 22.1 >> >> When ever the first column has a 'AMA;' I need to then pre/post a '@' >> at each number on that row, >> so I have something: >> 775.2 89.2 96.1 >> 234 384 441.4 >> AMA @8422@ @30@ @28@ >> 99 82 10.3 >> AMA @9.23@ @331@ @22.1@ > [...] > > sed '/AMA/ s/\([0-9]\{1,\}\.*[0-9]\{0,\}\)/ @\1@ /g' infile One command and so many errors ... sed '/^AMA/s/\([0-9.]\{1,\}\)/@\1@/g' infile Regards, Dimitre |
|
![]() |
| Outils de la discussion | |
|
|