1833776 Members
1950 Online
110063 Solutions
New Discussion

Re: awk help

 
Shahul
Esteemed Contributor

awk help


Hi

Can I format the output by using awk. I know it is possible thru printf. But I read it somewhere that awk can do this. but remembering the format. Can some one help me out?

Thanks in advance
Shahul
3 REPLIES 3
Darren Prior
Honored Contributor

Re: awk help

Hi Shahul,

Yup, printf is what you're looking for; check out man 3 printf for the specific format string you need.

regards,

Darren.
Calm down. It's only ones and zeros...
V.Tamilvanan
Honored Contributor

Re: awk help

Hi,

Ex:
awk '{printf("hi00%2.0f \n", NR+9)}

---------------------------
Formatted printouts are of the form printf( "format\n", value1, value2, ... valueN)
e.g. printf("howdy %-8s What it is bro. %.2f\n", $1, $2*$3)
%s = string
%-8s = 8 character string left justified
%.2f = number with 2 places after .
%6.2f = field 6 chars with 2 chars after .
\n is newline
\t is a tab

--------
HTH
-tamil
Andreas Voss
Honored Contributor

Re: awk help

Hi,

what kind of data do you want to format ?

Numeric integer:
printf("%06d\n", var);
will print integer with leading nulls
Float:
printf("%8.2f\n", var);
will print floating with decimal precision of two.

Regards