Solved

awk/php/perl questions

Posted on 2010-09-23
2
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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.
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.:
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…

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