Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed to divide a dec number by 10

Status
Not open for further replies.

viclap

Programmer
Oct 12, 2000
39
PH
Hi to all,

I'm new to sed and would like to know what would be the correct syntax on how to divide the a decimal number by 10 (2nd and 4th column) then the result would be on another file.

Sample Data:

John, 123 ,xxx, 100
David, 223, yyy, 145
Smith, 178, ccc , 240

Result would be:

John, 12.3 ,xxx, 10.0
David, 22.3, yyy, 14.5
Smith, 17.8, ccc , 24.0

Any help would be gladly apreciated....

Thank you
 
I'd use awk

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'd rather use awk if that would be the solution to my problem....

Thanks.
 
Thanks for the help. Have tried this solution through awk and it really works.

awk -F ',' '{print $4/10'}' InputFile > OutputFile


Tyvm.
 
Just for completeness, here's the [tt]sed[/tt] solution...

Code:
sed 's/\([0-9]\)\([0-9]\)$/\1.\2/1'  Infile

It's not really dividing by 10, it's just inserting a decimal. The [tt]awk[/tt] solution is the correct one.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top