- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need help with a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2006 10:33 PM
06-19-2006 10:33 PM
I have 6 files in the following directory -
(named like this)
/tmp/file1
/tmp/file-2
/tmp/file-3
/tmp/file-4
/tmp/file-5
/tmp/file-6
Each file contains the following:
Tue Jun 20 2006 06:30AM EDT
I need to open each file - grab the last field (0.66) - sum it with all of the numbers out of the other field - take an average- and place that number in a field.
I had done it by using, cat, awk, assigning the number to variable, and then adding all of up and dividing by 6.
I am a beginner at shell scripting so I am sure there is a more "elegant" way to do this, and I would be very interested to see other perspectives.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2006 10:50 PM
06-19-2006 10:50 PM
Re: need help with a script
But here is what you can do
for i in file1 file-2 file-3 file-4 file-5 file-6
do
awk '{tot+=$NF} END {print tot/NR}' $i
done
Please let know if you have any other requirement than above
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2006 11:01 PM
06-19-2006 11:01 PM
Re: need help with a script
Additionally, I need to average these 6 numbers, and be able to place the average in a file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2006 11:25 PM
06-19-2006 11:25 PM
Re: need help with a script
1.You want to the sum of last fields and you want to perform this for each file
2. Then you want to average these sums
What I initially thought was you want average for each individual files.
If I have now understood what you want here it is
sum1=$(awk '{tot+=$NF}' file1)
sum2=$(awk '{tot+=$NF}' file-2)
sum3=$(awk '{tot+=$NF}' file-3)
sum4=$(awk '{tot+=$NF}' file-4)
sum5=$(awk '{tot+=$NF}' file-5)
sum6=$(awk '{tot+=$NF}' file-6)
average=$(echo "($sum1 + $sum2 + $sum3 + $sum4 + $sum5 + $sum6)/6" | bc)
echo $average >> output file
Is this what you require ?
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2006 12:23 AM
06-20-2006 12:23 AM
Re: need help with a script
top=0
i=0
for f in /tmp/file*
do
xx=`(cat $f | grep EDT | cut -f8 -d' ')`
top=`echo $top + $xx | bc`
i=`expr $i + 1`
done
ort=`(echo $top / $i | bc -l)`
echo $ort > result.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2006 03:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2006 03:58 AM
06-20-2006 03:58 AM
Re: need help with a script
I think since the filename for 1st file is without a - there needs to be a bit of modification to your one liner.
Nice one.
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2006 03:43 AM
06-21-2006 03:43 AM
Re: need help with a script
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=824451
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 07:44 AM
06-29-2006 07:44 AM