Computing.Net > Forums > Unix > Help w/ awk problem? Will pay!

Help w/ awk problem? Will pay!

Reply to Message Icon

Original Message
Name: Sean
Date: October 15, 2002 at 14:30:57 Pacific
Subject: Help w/ awk problem? Will pay!
OS: Unix Solaris 7
CPU/Ram: ?
Comment:

I am a Windows user trying to learn how to use Unix, so forgive me if
I need short-bus type answers.

Can someone help me with this issue? I need to use an awk script on a
file. the file has 3 fields. The first and second fields are
strings, the third is an integer.

I need separate scripts to:

1: -Print out only the third field if the 1st field contains a certain
word
-Then print only the lowest value of field 3 and the field 2 that
matches it.

2. -display all entries in field 2 (without duplicating the same
name).

3. -print out list of field 2 and 3, but only if field 3 integer value
is less than 50, and the entire list sorted by field 3 from highest
value to lowest.

4. -print the average of the values of field 3, but only for the
fields that match a value in field 2.

Any help is greatly appreciated. I can pay you through paypal if this
help can be received by midnight, MDT, 10-15-02. Email me for
details: spdivr@hotmail.com

Thanks!


Report Offensive Message For Removal


Response Number 1
Name: James Boothe
Date: October 15, 2002 at 16:22:53 Pacific
Reply: (edit)

A sample of your data file is always helpful. I will assume that the 3 fields are white-space delimited, and those first two string fields do not have any embedded spaces.

It looks like you want four separate reports since each of those are selecting a different set of lines.

For Report #1 and #4, you need to plug your selection word in place of aaaa. The script could of course be changed to receive those as parameters.

These 4 reports tested fine on HP-UX 11.00.

#!/bin/sh

echo '\nReport #1 ...'
awk '$1=="aaaa" {\
printf "%10d\n",$3
if (flag==0 || f3low>$3)
{f3low=$3
f2hold=$2
flag=1}
}
END {\
printf "Lowest field3: %10d (%s)\n",f3low,f2hold}' myfile

echo '\nReport #2 ...'
awk '{print $2}' myfile |
sort -u

echo '\nReport #3 ...'
awk '50>$3 {printf "%9d %s\n",$3,$2}' myfile |
sort -r

echo '\nReport #4 ...'
awk '$2=="aaaa" {\
f3k++;f3=f3+$3}
END {\
if (f3k==0)
avg=0
else
avg=f3/f3k
printf "Matches: %6d avg: %10.2f\n",f3k,avg}' myfile


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Help w/ awk problem?  Will pay!

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge