Solved

perl or shell to round last column to hundredths place

Posted on 2011-09-22
4
315 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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linux pull logs and export FTP 4 71
Online Forms 6 59
Help With Shell Script Centos 6 6 53
read an xml file in perl 2 32
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

777 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