Solved

awk/php/perl questions

Posted on 2010-09-23
2
253 Views
Last Modified: 2013-12-26
Hi

i have the following three statements in  a perl script

as you can see they compute avg, min and max from the second column of a two digit column file...

can i somehow combine the statements into just 1 statement...it seems a bit stretched to ghave 3 statements processing the file 3 times....

$a=`nawk 'NR==1{k=0;Sum=0}{k=k+1; Sum=Sum+$2}END{print  k "  Records found" }' d
ata`;
$avg = `nawk 'NR==1{k=0;Sum=0}{k=k+1; Sum=Sum+$2}END{print "<b>Avg</b> = "Sum/k
}' data`;
$min = `awk 'min=="" || $2 < min {min=$2} END{ print min}' data`;
$max = `awk 'max=="" || $2 > max {max=$2} END{ print max}' data`;

the file looks like this:

11111     8.77777
22222     98.0000

and so on




0
Comment
Question by:Vlearns
2 Comments
 

Author Comment

by:Vlearns
Comment Utility
its inside a php  script actually
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
nawk 'NR==1{k=0;Sum=0}{k=k+1; Sum=Sum+$2}min=="" || $2 < min {min=$2}max=="" || $2 > max {max=$2}END{print  k "  Records found"; print "<b>Avg</b> = "Sum/k; print min; print max }' data
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

744 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