Operating System - HP-UX
1832300 Members
1696 Online
110041 Solutions
New Discussion

Re: Need to append 692 blanco positions to end of string

 
SOLVED
Go to solution
Frank de Vries
Respected Contributor

Need to append 692 blanco positions to end of string

I have a file with this contents,
6000 lines. (extract below)

*** HEADER ***
2006474@0001@1K
2006474@0002@1K
2006474@0003@1K
2006474@0004@1K
2006474@0005@1K
2006474@0006@1K
2006474@0007@1K

we need to append 692 blanco spaces after the 1K.

The only way I can thing of is to do
sed 's/1K/1K < here count 692 spaces /g

but that is a bit silly, besides there is a to lose count.
Is there a shorter way to do it , or with another tool like awk or perl ?
Look before you leap
4 REPLIES 4
Peter Godron
Honored Contributor

Re: Need to append 692 blanco positions to end of string

Frank,
in perl you have the string-repetition Operator (x):
$addstring = " " x 692;
$newstring = $oldstring . $addstring

In shell you could run a little loop 692 times to build up your addstring and then append to the existing record
Frank de Vries
Respected Contributor

Re: Need to append 692 blanco positions to end of string

ta
I found also a solution with cut and paste
in a whlle loop.
Look before you leap
Dennis Handly
Acclaimed Contributor
Solution

Re: Need to append 692 blanco positions to end of string

>Peter: In shell you could run a little loop 692 times to build up your addstring

(I assume you are smart enough to do 2 or more at a time? ;-)

You can use awk's printf to add the 692 spaces:
awk '{ printf "%s%692s\n", $0,""}' in-file
Frank de Vries
Respected Contributor

Re: Need to append 692 blanco positions to end of string

thanks Dennis ,
that was exactly what I was looking for !!
Brilliant !!
Look before you leap