Solved

perl or shell to round last column to hundredths place

Posted on 2011-09-22
4
312 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:
ddsh79 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now