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 replace first five chars
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

sed replace first five chars

Réponse
 
LinkBack Outils de la discussion
Vieux 01/11/2006, 20h09   #1
NoManKey
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sed replace first five chars

Hi - I have a file that contains a series of fields that I need to
retain but into which I need to insert a new field.

The new field has to be the first field and consist of 8 characters
broken down as a five digit number (preferably starting as 00001)
followed by 3 spaces. The number being inserted into the first field
needs to be incremented on each subsequent line.

Is this a simple one or trickier than it sounds???

example structure - fixed field lengths (12,12,11,12)
874647864 Alan 01/01/06 comment1
874667865 Harry 01/10/06 comment2
874697866 malcolm 10/01/06 comment3

required structure (8,12,12,11,12)
00001 874647864 Alan 01/01/06 comment1
00002 874667865 Harry 01/10/06 comment2
00003 874697866 malcolm 10/01/06 comment3

TIA

  Réponse avec citation
Vieux 01/11/2006, 20h19   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace first five chars

NoManKey wrote:
> Hi - I have a file that contains a series of fields that I need to
> retain but into which I need to insert a new field.
>
> The new field has to be the first field and consist of 8 characters
> broken down as a five digit number (preferably starting as 00001)
> followed by 3 spaces. The number being inserted into the first field
> needs to be incremented on each subsequent line.
>
> Is this a simple one or trickier than it sounds???
>
> example structure - fixed field lengths (12,12,11,12)
> 874647864 Alan 01/01/06 comment1
> 874667865 Harry 01/10/06 comment2
> 874697866 malcolm 10/01/06 comment3
>
> required structure (8,12,12,11,12)
> 00001 874647864 Alan 01/01/06 comment1
> 00002 874667865 Harry 01/10/06 comment2
> 00003 874697866 malcolm 10/01/06 comment3
>
> TIA
>


awk '{printf "%05d %s\n", NR, $0}'


Janis
  Réponse avec citation
Vieux 01/11/2006, 20h20   #3
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace first five chars

NoManKey wrote:

> Hi - I have a file that contains a series of fields that I need to
> retain but into which I need to insert a new field.
>
> The new field has to be the first field and consist of 8 characters
> broken down as a five digit number (preferably starting as 00001)
> followed by 3 spaces. The number being inserted into the first field
> needs to be incremented on each subsequent line.
>
> Is this a simple one or trickier than it sounds???
>
> example structure - fixed field lengths (12,12,11,12)
> 874647864 Alan 01/01/06 comment1
> 874667865 Harry 01/10/06 comment2
> 874697866 malcolm 10/01/06 comment3
>
> required structure (8,12,12,11,12)
> 00001 874647864 Alan 01/01/06 comment1
> 00002 874667865 Harry 01/10/06 comment2
> 00003 874697866 malcolm 10/01/06 comment3
>


$ cat file
874647864 Alan 01/01/06 comment1
874667865 Harry 01/10/06 comment2
874697866 malcolm 10/01/06 comment3
$ awk '{printf "%05d %s\n",NR,$0}' file
00001 874647864 Alan 01/01/06 comment1
00002 874667865 Harry 01/10/06 comment2
00003 874697866 malcolm 10/01/06 comment3

Regards,

Ed.
  Réponse avec citation
Vieux 01/11/2006, 20h25   #4
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sed replace first five chars

NoManKey <nomadic.monkey@gmail.com> wrote:
> Hi - I have a file that contains a series of fields that I need to
> retain but into which I need to insert a new field.
>
> The new field has to be the first field and consist of 8 characters
> broken down as a five digit number (preferably starting as 00001)
> followed by 3 spaces. The number being inserted into the first field
> needs to be incremented on each subsequent line.
>
> Is this a simple one or trickier than it sounds???


awk '{ printf("%05d %s\n", NR, $0) }' /your/file

--
Daniel
  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 22h13.


É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 0,11752 seconds with 12 queries