- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: script question
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
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-14-2005 08:22 AM
06-14-2005 08:22 AM
I started like this...
***
sort /usr/contrib/scripts/example >>$WORKPATH/$WORKFILE
cat $WORKPATH/$WORKFILE |while read SSN HOURS
do
let TOTAL=TOTAL+HOURS
echo $SSN $HOURS$TOTAL >> $WORKPATH/example.totals
done
***
I dont really need the total, just sub-totals by the first field - Any ideas are greatly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 08:36 AM
06-14-2005 08:36 AM
Re: script question
for i in $(cat "your_file"|awk '{print $1}')
do
if [[ ${i} = ${total} ]]
then
echo "$i = ${total}"
fi
done
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 08:37 AM
06-14-2005 08:37 AM
Re: script question
do
grep $SSN $WORKFILE > /tmp/sometempfile
tot=0
cat /tmp/sometempfile|while read SSN HOURS
do
let tot=$tot+$HOURS
done
echo $SSN" has "$tot" total hours"
done
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 08:45 AM
06-14-2005 08:45 AM
SolutionCreate an awk script, my.awk :
{
if ($1 in arry) arry[$1] += ($2 + 0)
else arry[$1] = ($2 + 0)
}
END {
for (i in arry)
{
printf("%-20.20s %9.2f\n",i,arry[i])
}
}
------------------------------------------
Now invoke it like this:
awk -f my.awk < myinfile | sort
I would create the awk script "on the fly" and include it in my shell script but this should get you started.
If the values to be summed are integers, change the %9.2f to %9d and similarly, you might want to change the %-20.20s format to %09d if the sunscripts are integer or %09.2f if the subscripts are floating point values. The format of the subscript only matters in the sorting of the output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 09:04 AM
06-14-2005 09:04 AM
Re: script question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2005 09:06 AM
06-14-2005 09:06 AM