- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Does anyone know this:? (Number processing!)
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
03-20-2006 05:36 PM
03-20-2006 05:36 PM
Q: Does anyone know , how add 5 numbers using dc ?
I have checked man page but not able to understand much. Nor I got a good guide to do this.
I can use this command to add 2 number , but unable to do more than 2.
# echo " 5 7 + p " | dc
12
#
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 06:04 PM
03-20-2006 06:04 PM
Re: Does anyone know this:? (Number processing!)
export p=9
echo "2+5+$p" |bc
All is fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 06:21 PM
03-20-2006 06:21 PM
Re: Does anyone know this:? (Number processing!)
Another way to add three number :
Hpux:/# let 'p=5+7'
Hpux:/# echo $p
Hpux:/# 12
Hpux:/# let 'q=5+7+p'
Hpux:/# echo $q
Hpux:/# 24
Hope this helps
Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 06:26 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 06:53 PM
03-20-2006 06:53 PM
Re: Does anyone know this:? (Number processing!)
for 5 number is would be:
# echo " 3 4 5 6 7 + + + + p"|dc
25
Why the use of dc?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 06:57 PM
03-20-2006 06:57 PM
Re: Does anyone know this:? (Number processing!)
if you can put it all in a file,
e.g.
12
23
34
45
45
56
you can then just do:
cat datafile.lis | awk '{sum=sum+$1} End {print sum}'
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 07:18 PM
03-20-2006 07:18 PM
Re: Does anyone know this:? (Number processing!)
To add 5 numbers using dc you could do either way
echo "5 +5 +5 +5 +5 +p"|dc
25
echo "5 5 5 5 5 +++++p"|dc
25
Indira A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 07:24 PM
03-20-2006 07:24 PM
Re: Does anyone know this:? (Number processing!)
# echo "5 7 9 11 13 + + + + p" | dc
More ways are there,
a) expr
b) awk
c) echo $(())
d) perl
etc.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 07:30 PM
03-20-2006 07:30 PM
Re: Does anyone know this:? (Number processing!)
Easiest way in perl,
# perl -e "print 10+20+30+40+50"
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 10:00 PM
03-20-2006 10:00 PM
Re: Does anyone know this:? (Number processing!)
You can use
# echo " 1 2 3 4 +++ p " | dc
10
#
You can also use :
1. awk
2. expr
3. echo
4. perl
5. sed
6. bc
Cheers,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2006 11:35 PM
03-20-2006 11:35 PM
Re: Does anyone know this:? (Number processing!)
The Logic with "dc" is simple, number of + signs = (n-1)
# echo "1 2 3 4 5 + + + + p" | dc
You need to specify four + signs here.
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2006 08:46 PM
03-21-2006 08:46 PM
Re: Does anyone know this:? (Number processing!)
why not?
echo "1+2+3+4+5"|bc
HTH,
Art