fprint syntax for repeating fields

  • Follow


Is there a repetition syntax for field formats in fprint?
I would like to compress repeating format fields so my format string doesn't
get so long and confusing....

example can:

printf "%10.3f%10.3f%10.3f\n", $1,$2,$3

be compressed into 3 fields in the same manner a fortran 3f10.3 ?

Rex


0
Reply foo (114) 5/9/2006 1:16:47 PM

In article <-ZSdnTjyNZoECP3ZnZ2dneKdnZydnZ2d@comcast.com>,
	"trexx" <foo@foo.com> writes:
> Is there a repetition syntax for field formats in fprint?

No.

> I would like to compress repeating format fields so my format string doesn't
> get so long and confusing....
> 
> example can:
> 
> printf "%10.3f%10.3f%10.3f\n", $1,$2,$3
> 
> be compressed into 3 fields in the same manner a fortran 3f10.3 ?

function rep(n,s  ,r)
{
    r = ""
    while( n-- > 0 ) r = r s
    return r
}

printf( rep(3,"%10.3f") "\n", $1,$2,$3 )
-- 
Heiner Marxen				http://www.drb.insel.de/~heiner/
-1
Reply heiner 5/9/2006 5:21:45 PM


Heiner Marxen wrote:

> In article <-ZSdnTjyNZoECP3ZnZ2dneKdnZydnZ2d@comcast.com>,
> 	"trexx" <foo@foo.com> writes:
> 
>>Is there a repetition syntax for field formats in fprint?
> 
> 
> No.
> 
> 
>>I would like to compress repeating format fields so my format string doesn't
>>get so long and confusing....
>>
>>example can:
>>
>>printf "%10.3f%10.3f%10.3f\n", $1,$2,$3
>>
>>be compressed into 3 fields in the same manner a fortran 3f10.3 ?
> 
> 
> function rep(n,s  ,r)
> {
>     r = ""
>     while( n-- > 0 ) r = r s
>     return r
> }
> 
> printf( rep(3,"%10.3f") "\n", $1,$2,$3 )
Alternatively, if s does not contain a space:

function rep(n, s       , r)
{
	r = sprintf("%*s", n, " ")
	gsub(/ /, s, r)
	return r
}

0
Reply martin 5/9/2006 6:11:47 PM

In article <FX48g.6$A82.1@dfw-service2.ext.ray.com>,
martin cohen  <mjcohen@acm.org> wrote:
....
>function rep(n, s       , r)
>{
>	r = sprintf("%*s", n, " ")
	r = sprintf("%*s", n, "")
>	gsub(/ /, s, r)
>	return r
>}
>

>Alternatively, if s does not contain a space:

Spaces don't matter.  gsub() does the right thing.

0
Reply gazelle 5/9/2006 6:30:28 PM

3 Replies
345 Views

(page loaded in 0.06 seconds)

Similiar Articles:













7/24/2012 12:16:21 AM


Reply: