1827295 Members
1628 Online
109960 Solutions
New Discussion

Formatted echo...

 
SOLVED
Go to solution
Rui Vilao
Regular Advisor

Formatted echo...

Hi,

Does anyone know how I could in a unix script produce a formated (3 digits) echo:

i=7
echo $i
i=30
echo $i

result should look like:

007
030

TIA,

Kind Regards,

Rui.
"We should never stop learning"_________ rui.vilao@rocketmail.com
4 REPLIES 4
Sebastien Masson
Valued Contributor

Re: Formatted echo...

echo $i | /usr/bin/awk '{printf "%03i", $0 }'
Rui Vilao
Regular Advisor

Re: Formatted echo...

I think there is a small mistake...
i=3

echo $i | /usr/bin/awk '{printf "%03i", $0 }'
%03ii

"We should never stop learning"_________ rui.vilao@rocketmail.com
Sebastien Masson
Valued Contributor
Solution

Re: Formatted echo...

Hmm..strange because it works for me.

# i=3
# echo $i | /usr/bin/awk '{printf "%03i", $0 }'
003


# what /usr/bin/awk
/usr/bin/awk:
$Revision: 82.2 $

I running that on HP-UX 11.00
Curtis Larson_1
Valued Contributor

Re: Formatted echo...

why not just use the system command printf
man 1 printf

i=3
printf "%03i\n" $i