Oracle DBA – A lifelong learning experience

    Advertisements
  • Meta

  • Categories

  • Blog Stats

    • 1,634,354 hits
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 376 other followers

Performing calculations in unix

Posted by John Hallas on August 31, 2009

Normally if I working on a database and want perform simple calculations I use the Oracle database rather than starting up the windows calculator.

select 6*1024*1024 from dual;

6*1024*1024
-----------
    6291456

 

However I recently found out a method of using unix itself (I am sure there are many more options other than this one but I find this quite easy)

man bc gives

bc is an interactive processor for a language that resembles C but provides unlimited-precision arithmetic.  It takes input from any  files given, then reads the standard input.

In usage

/home/oracle $bc
6*1024*1024
6291456
quit

Arithmetic operators are shown in the normal manner + – * / % ^ and there are lots of functions available such as sine, cosine and log, although I would be likely to use a calculator if I wanted to use these.

Advertisements

6 Responses to “Performing calculations in unix”

  1. danirey said

    Thanks for sharing. When using Linux with KDE I prefer to do calculations in the “run command” window (works only with KDE < Version 4)

    You can usually open the "run command" dialog with Alt+F2, or in the KDE Menu. If you want to proceed with results 0.2342 Otherwise it’s not recognized as a number.

  2. pgreenwood said

    I go to python for quick calculations.

    • John Hallas said

      Thanks Patrick, there are lots of ways of doing calculations using shell, perl, python bit I found bc nice and easy (and there is an alternative dc which looks very simple as well)

  3. lbolla said

    I strongly recommend you:
    $> bc -l

    otherwise 1/2 = 0, instead of 0.5!
    L

  4. […] John Hallas – Performing calculations in unix […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: