Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > fprint syntax for repeating fields
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 11th September 03:23
trexx
External User
 
Posts: 1
Default fprint syntax for repeating fields



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
  Reply With Quote


 


2 11th September 03:23
heiner
External User
 
Posts: 1
Default fprint syntax for repeating fields



In article <-ZSdnTjyNZoECP3ZnZ2dneKdnZydnZ2d@comcast.com>,
"trexx" <foo@foo.com> writes:


No.


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/
  Reply With Quote
3 11th September 03:23
martin cohen
External User
 
Posts: 1
Default fprint syntax for repeating fields


Alternatively, if s does not contain a space:

function rep(n, s , r)
{
r = sprintf("%*s", n, " ")
gsub(/ /, s, r)
return r
}
  Reply With Quote
4 11th September 03:23
gazelle
External User
 
Posts: 1
Default rep() function (Was: fprint syntax for repeating fields)


r = sprintf("%*s", n, "")


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


Thread Tools
Display Modes




666