Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

perl or shell to round last column to hundredths place

Posted on 2011-09-22
4
Medium Priority
?
325 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
4 Comments
 
LVL 28

Expert Comment

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

Accepted Solution

by:
Dushyant Sharma earned 1000 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
What we learned in Webroot's webinar on multi-vector protection.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Six Sigma Control Plans

963 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