Solved

awk/php/perl questions

Posted on 2010-09-23
2
255 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

867 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

22 Experts available now in Live!

Get 1:1 Help Now