?
Solved

calculating average of different input files

Posted on 2006-03-25
3
Medium Priority
?
249 Views
Last Modified: 2012-06-27
Hi everyone!

Currently using awk to carry out tasks within a bash script.

I'm having difficulty carrying out tasks with each individual file being read in as a command-line argument. For example, I can calculate the average records from all files but not the average record from each file.  The amount of filenames read in as command-line arguments is unlimited so I have been using $* as the input for my awk script.  

I tried using the following conditions to resolve this problem but was of no consequence:

for (x =1; x < ARGC; x++){
if (ARGV[x] = FILENAME){
}
}

Your help would be much appreciated
0
Comment
Question by:london_town
3 Comments
 
LVL 3

Expert Comment

by:leisner
ID: 16290880
I'm a bit confused.

You have an awk script to compute the average for a file...

Do you want to do something like:

for i in $*
do
         average=$(awk-script $i)
         echo for $i the average is $average
done

0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 16290935
awk 'prev!=FILENAME{if(n){ print prev, total/n; } n=0; total=0; prev=FILENAME}{n++;total+=$1}END{ if(n){ print prev, total/n; } }' $*
0
 

Author Comment

by:london_town
ID: 16291645
Thanks guys!
Spot on ozo, could not continue my script without this assistance.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

809 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