- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- BC to add items in a collumn
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
04-17-2007 02:50 AM
04-17-2007 02:50 AM
143413413
412342346
432434877
434978867
432654657
How would I use bc to cat this file and add the numbers?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 02:54 AM
04-17-2007 02:54 AM
Re: BC to add items in a collumn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 02:56 AM
04-17-2007 02:56 AM
Re: BC to add items in a collumn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 03:07 AM
04-17-2007 03:07 AM
Re: BC to add items in a collumn
found on an old website:
#!/bin/ksh
TOTAL=0
for NUMBER in `cat
do
TOTAL=`echo $NUMBER + $TOTAL |bc -l`
done
echo $TOTAL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 03:15 AM
04-17-2007 03:15 AM
Re: BC to add items in a collumn
TF="/var/tmp/TF${$}"
trap 'eval rm -f ${TF}' 0 1 2 3 15
INFILE=myfile
echo "a=0" > ${TF}
cat ${INFILE} | while read N
do
echo "a+=${N}" >> ${TF}
done
echo "a" >> ${TF}
TOT=$(bc < ${TF})
echo "Total: ${TOT}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 03:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 03:56 AM
04-17-2007 03:56 AM
Re: BC to add items in a collumn
a solution with dc:
(sed '2,$s/$/+/' /tmp/num; print p) | dc
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 04:41 AM
04-17-2007 04:41 AM
Re: BC to add items in a collumn
# p=0; while read l;do p=$(echo "$l + $p" | bc); done < infile;echo $p
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 05:50 AM
04-17-2007 05:50 AM
Re: BC to add items in a collumn
Unacceptable.
Please explain.
Sure you can.
Apparently you can not use BC either, so why not use / learn somethign much more versatile and useful in the long run.
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 05:56 AM
04-17-2007 05:56 AM
Re: BC to add items in a collumn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2007 06:58 AM
04-17-2007 06:58 AM
Re: BC to add items in a collumn
You may not have liked my answer and that's ok, but please humor me and explain why it had to be 'bc' and why you had to 'cat' the file. I'm curious and always eager to learn!
Regards,
Hein.