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