?
Solved

awk/php/perl questions

Posted on 2010-09-23
2
Medium Priority
?
265 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 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…
Suggested Courses

770 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