Insert decimal point for numbers

Hi

In Unix, I have a file with some numbers like :

45600
12345

I want to insert a decimal point for these numbers based on user input.
If the input is 2, the numbers should be changed to

456.00
123.45

If the input is 3, the numbers should be changed to

45.600
12.345

Can this be doen with any Unix commands or sed ?
Any help appreciated.

$ cat file1
45600
12345

$ awk '{printf( "%." C "f\n", $1 / 10^C) }' C=1 file1
4560.0
1234.5

$ awk '{printf( "%." C "f\n", $1 / 10^C) }' C=2 file1
456.00
123.45

$ awk '{printf( "%." C "f\n", $1 / 10^C) }' C=3 file1
45.600
12.345

$ awk '{printf( "%." C "f\n", $1 / 10^C) }' C=4 file1
4.5600
1.2345

Hi Scottn,

Works perfectly ! Thanks alot !
Could you take the trouble to explain the core part :

"%." C "f\n", $1 / 10^C

Thanks again :slight_smile:

---------- Post updated at 06:08 AM ---------- Previous update was at 06:01 AM ----------

Ok. I understood it. Really good one !!