Adding Text To |bc Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding Text To |bc Output
# 1  
Old 04-21-2010
Power Adding Text To |bc Output

Hello.

I have this..
Code:
$ echo '2+2' | bc
4

But I want to output it as
Code:
4 MB

So, can I achieve that through one single command line?

Thank you.
# 2  
Old 04-22-2010
Code:
$ a=`echo '2+2' | bc` && echo $a MB
4 MB

# 3  
Old 04-22-2010
Bug

Quote:
Originally Posted by pseudocoder
Code:
$ a=`echo '2+2' | bc` && echo $a MB
4 MB

Thank you so much pseudocoder.

Really appreciate.. Smilie

Btw, could you please explain details? Is that && is equivalent to || in Oracle?

Thank you.
# 4  
Old 04-22-2010
You are welcome.
Code:
&& = AND
|| = OR

HTH

Regards
# 5  
Old 04-22-2010
If you just want to do some basic integer arithmetic, you don't have to use bc. Shell arithmetic substitution should suffice:
Code:
$ echo $((2+2)) MB
4 MB

# 6  
Old 04-22-2010
Bug

Quote:
Originally Posted by alister
If you just want to do some basic integer arithmetic, you don't have to use bc. Shell arithmetic substitution should suffice:
Code:
$ echo $((2+2)) MB
4 MB

Wow.. I don't know that could be possible.

Thank you very much! Smilie
# 7  
Old 04-22-2010
Quote:
Originally Posted by alister
If you just want to do some basic integer arithmetic, you don't have to use bc. Shell arithmetic substitution should suffice:
Code:
$ echo $((2+2)) MB
4 MB




This is possible only with BASH and KSH but not with SH and CSH shells.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding hostname on the output

// AIX 6.1 pcmpath query device |awk 'BEGIN{print "TYPE\tDEVICE NAME\tSERIAL\tSIZE"} /DEVICE/ {disk=$5 printf "%s\t", $7 printf "%s\t", disk getline; printf "%s\t", substr($2, length($2)-3) ("bootinfo -s "... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

2. Shell Programming and Scripting

Adding more text to a variable

Is there a more simple way to add text to a variable I havevar="blue" and like to add green to getecho $var blue green Here is how I do it. var=$(echo "${var} green") ---------- Post updated at 13:23 ---------- Previous update was at 13:12 ---------- :o Uff Not always easy to see the... (2 Replies)
Discussion started by: Jotne
2 Replies

3. Shell Programming and Scripting

adding text with sed

sed 's/<\/body>/<A HREF='"$index"'>'"$description"'<\/A>\ <\/body>/' "$index" This will work from the command prompt, but not from my ksh script. Why not? sed: command garbled: s/<\/body>/<A HREF=/accounts/students/b/bmwg6c/public_html/index.html>I would like to call it white... (4 Replies)
Discussion started by: robin_simple
4 Replies

4. Shell Programming and Scripting

Adding and then separating the output

Hi I have this output /vol/vol0 4GB /vol/nonprod00 682GB /vol/prod00 3GB /vol/nasp_archive 201GB /vol/nasp_iface 92GB /vol/nasp_bsi 0GB /vol/nasp_vertex 0GB /vol/nasp_sapmnt_mp2 1GB /vol/nasp_sapmnt_prd 52GB /vol/nasp_sapmnt_srp 1GB /vol/nasp_smd 1GB /vol/nasp_ccms 0GB... (8 Replies)
Discussion started by: bombcan
8 Replies

5. Shell Programming and Scripting

adding text before and after a word

Hello, I have a list: i.e: 40331786 50331787 30331788 30331789 30331790 50331791 50331792 50331793 70331794 70331795 70331796 ... ... and I need to add text before and after each number: (2 Replies)
Discussion started by: drbiloukos
2 Replies

6. Shell Programming and Scripting

Adding text into file

Hello, I after some assistance please. Below is a file I need to read and for each line write an output. My input file looks like this 2 20008 2003-08-26 2 20032 2003-08-26 2 20041 2003-08-26 2 20037 2003-08-26 2 20050 2003-08-26 6 ... (6 Replies)
Discussion started by: giles.cardew
6 Replies

7. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

8. Shell Programming and Scripting

adding another field to SED output

Dear experts, I have a file called "check" with contents like below i used the sed command like below to get the value of "success" and "failed" only My question is how can i get the value to include the time "03:15", so that i can get a value such as below : - Appreciate... (4 Replies)
Discussion started by: aismann
4 Replies

9. Shell Programming and Scripting

adding text to a file

Hi All I am making a script in which.I have a problem i try to discribe. File1 content need to be append in file 2 but such as if content already exist then dont add. File1 IS Like this myname yourname hername hisname File2 %AddNameHere myname yourname hername hisname (3 Replies)
Discussion started by: aliahsan81
3 Replies

10. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies
Login or Register to Ask a Question