Having problem trying to.. 
Author Message
 Having problem trying to..

I am trying to do a fairly simple job in awk and am having trouble.
Can anybody give me some suggestions.

I want to output a field with a set width of 8charcters.
The field is an integer and I want the left hand side padded
with zeros.

So for example my input in 9723 I want the output
to be 00009723.

I have tried using printf "%8s", $1 but this just white spaces
so I get '    9723'.

Could someone please EMAIL me how to do this.

Again please email me as I don't read news online.




Fri, 04 Sep 1998 03:00:00 GMT  
 Having problem trying to..
:
: The field is an integer and I want the left hand side padded
: with zeros.
:
: So for example my input in 9723 I want the output
: to be 00009723.
:

print substr("00000000" $1,length($1 " "))

This will create a string with 8 zeros followed by the number ($1),
and take all of the resulting string from the position which is
1 plus the length of the string of the number .

The number of zero's indicate the number of digits in the result.

It doesn't work for a negative number though.

: Could someone please EMAIL me how to do this.

I did, but I thought it'd be nice to post it as well

Have fun,

Jelle Paul

--
+-------------------------------------------------------+

| Vrije Universiteit Amsterdam    |                     |
+-------------------------------------------------------+



Sat, 05 Sep 1998 03:00:00 GMT  
 Having problem trying to..

Quote:

> I am trying to do a fairly simple job in awk and am having trouble.
> Can anybody give me some suggestions.

> I want to output a field with a set width of 8charcters.
> The field is an integer and I want the left hand side padded
> with zeros.

> So for example my input in 9723 I want the output
> to be 00009723.

> I have tried using printf "%8s", $1 but this just white spaces
> so I get '    9723'.

> Could someone please EMAIL me how to do this.

> Again please email me as I don't read news online.



   Mark,
   try format "%.8d". It worked for me.

   On a whole, format description is available in man page for "printf". Format you have supplied treats output as a string, and not as an integer.

   Be-hatzlaha.

+-----------------------------------------------------------------+
|  Mark Geyser                      Phone: +972-8-9273398         |

|                                                                 |
|  "In every one of your good deeds (if any) - don't overdo it"   |
+-----------------------------------------------------------------+



Sat, 05 Sep 1998 03:00:00 GMT  
 Having problem trying to..

: I am trying to do a fairly simple job in awk and am having trouble.
: Can anybody give me some suggestions.

: I want to output a field with a set width of 8charcters.
: The field is an integer and I want the left hand side padded
: with zeros.

: So for example my input in 9723 I want the output
: to be 00009723.

: I have tried using printf "%8s", $1 but this just white spaces
: so I get '    9723'.

Try printf("%08d", $1)

Cheers
Terry Purdon



Sat, 05 Sep 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Try this if you are having problems getting action out of your joystick

2. try gfdg try kuiou try gsdfas try

3. Having problems changing printer settings within the program code (anyone having problems w/ OkiData printers?)

4. Having problem starting DST

5. I'm having a cpu problem

6. Novice having merge problem

7. Any IFT server experts, having WAP problem?

8. Still having OCX Problems

9. Still Having File Open Problem

10. Still having problems with C4 ABC Conversion

11. Still having problems with updating record from browse

12. Having a problem finding caci.ini????

 

 
Powered by phpBB® Forum Software