Solved

awk/php/perl questions

Posted on 2010-09-23
2
261 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
ID: 33748703
its inside a php  script actually
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 33751922
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

696 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