PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > sed inserting a @ before and after a number found
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

sed inserting a @ before and after a number found

Réponse
 
LinkBack Outils de la discussion
Vieux 01/12/2006, 14h08   #1
peter_sands@techemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sed inserting a @ before and after a number found

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

  Réponse avec citation
Vieux 01/12/2006, 14h21   #2
Eric Moors
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed inserting a @ before and after a number found

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
  Réponse avec citation
Vieux 01/12/2006, 14h34   #3
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed inserting a @ before and after a number found


<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


  Réponse avec citation
Vieux 01/12/2006, 14h35   #4
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed inserting a @ before and after a number found

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
  Réponse avec citation
Vieux 01/12/2006, 14h43   #5
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed inserting a @ before and after a number found

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
>
>

  Réponse avec citation
Vieux 01/12/2006, 14h47   #6
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed inserting a @ before and after a number found

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
  Réponse avec citation
Vieux 01/12/2006, 15h20   #7
Radoulov, Dimitre
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed inserting a @ before and after a number found


"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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h52.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 1,23130 seconds with 15 queries