INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

sed to divide a dec number by 10

sed to divide a dec number by 10

(OP)
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

RE: sed to divide a dec number by 10

(OP)
I'd rather use awk if that would be the solution to my problem....

Thanks.

RE: sed to divide a dec number by 10

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

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


Tyvm.

RE: sed to divide a dec number by 10

Just for completeness, here's the sed 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 awk solution is the correct one.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close