Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# awk/php/perl questions

Posted on 2010-09-23
Medium Priority
268 Views
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
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

Author Comment

ID: 33748703
its inside a php  script actually
0

LVL 84

Accepted Solution

ozo earned 2000 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

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
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.
###### Suggested Courses
Course of the Month9 days, 4 hours left to enroll