1748169 Members
4094 Online
108758 Solutions
New Discussion юеВ

Shell scripting help

 
SOLVED
Go to solution
Karthik S S
Honored Contributor

Shell scripting help

Hi,

My file looks like this:

cat 123
70
82.1
12.34
11
10
125

I want to modify the o/p to look like this:
70.00
82.10
12.34
11.00
10.00
125.00

any help is appreciated

thanks,
Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: Shell scripting help

Hi:

# cat .reformat
#!/usr/bin/sh
while read NUM X
do
printf "%.2f\n" ${NUM}
done < ./123

Regards!

...JRF...
Karthik S S
Honored Contributor

Re: Shell scripting help

Thank you! it works :)
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
James R. Ferguson
Acclaimed Contributor

Re: Shell scripting help

Hi (again):

Of course you can type less if you use 'awk':

# awk '{printf "%.2f\n",$1}' file

Regards!

...JRF...
Karthik S S
Honored Contributor

Re: Shell scripting help

Thank you James, that was very helpful (especially the awk one)
-Karthik
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn