Solved

perl or shell to round last column to hundredths place

Posted on 2011-09-22
4
320 Views
Last Modified: 2012-05-12
perl or shell to round last column to hundredths place. I have a sample file below.
so4pap.txt
0
Comment
Question by:libertyforall2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 28

Expert Comment

by:FishMonger
ID: 36584933
What have you tried?
0
 
LVL 14

Accepted Solution

by:
Dushyant Sharma earned 250 total points
ID: 36585708
awk '{print $1 " " $2 " " $3 " "  $4/1}' so4pap.txt

you need to set the scale
0
 
LVL 9

Assisted Solution

by:parparov
parparov earned 250 total points
ID: 36588104
Usage: script.pl < so4pap.txt

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
	chomp;
	my @data = split(/\s+/);
	$data[-1] = sprintf("%0.2f\n", $data[-1]);
	print join(" ", @data);
}

Open in new window

0
 

Author Closing Comment

by:libertyforall2
ID: 36898437
Great!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Six Sigma Control Plans

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question