Sponsored Content
Full Discussion: help with adding up numbers
Top Forums Shell Programming and Scripting help with adding up numbers Post 302661849 by aksijain on Monday 25th of June 2012 10:25:09 PM
Old 06-25-2012
help with adding up numbers

I have a file which has following contents which I want to add up.

Code:
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
28170.24
139038.72
139038.72
139038.72
139038.72
139038.72
139038.72
139038.72
139038.72
139038.72


Now when I use
Code:
paste -s -d+ <file-name>

it gives the string that I am looking for.
Code:
+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+21125.12+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+21125.12+14080.00+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24+28170.24

But when I give
Code:
paste -s -d+ <file-name> | bc

I do not get any output. Smilie

Even for loop fails with error..

Code:
bash: ((: 139038.72: syntax error in expression (error token is ".72")
bash: ((: 139038.72: syntax error in expression (error token is ".72")
bash: ((: 139038.72: syntax error in expression (error token is ".72")
bash: ((: 139038.72: syntax error in expression (error token is ".72")


Last edited by Scrutinizer; 06-26-2012 at 02:12 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding 2 numbers

I would like to write a script with BASH to add two numbers (integer) and write the result to the standard output. Please help! (7 Replies)
Discussion started by: Viper01
7 Replies

2. Shell Programming and Scripting

adding a list of numbers 3 by 3

i have a list of numbers like this; 124 235 764 782 765 451 983 909 ... and i want to make a sum with the first 3 of them then the next 3 and so on. 124+235+764=1123 782+765+451=1998 ... some ideas? (4 Replies)
Discussion started by: Tártaro
4 Replies

3. UNIX for Dummies Questions & Answers

adding hundreds of numbers

i know how to add two numbers using expr, but if i have a file with hundreds of numbers, how do i add them all together, without typing them all one by one? for example, file.txt contains 4 5 6 7 how can i give a command to add them, without typing $ expr `4 + 5 + 6 + 7` (7 Replies)
Discussion started by: FOBoy
7 Replies

4. UNIX for Dummies Questions & Answers

Adding numbers in unix

Hi this is quite a simple question... I am new to LINUX/UNIX and so I am just trying to create a very basic program. The idea is that when the user runs the program (from the shell) they enter 3 values and the program will add them up: "./sum 23 5 1 29" my code for this program is as follows: ... (4 Replies)
Discussion started by: csuieb
4 Replies

5. Shell Programming and Scripting

Adding numbers

Hi I figured how to add my list of numbers. However how do I count so that after a certain number it lists the line. Example: 12 test1 46 test2 195 test3 174 test4 634 test5 185 test6 94 test7 So basically add the numbers and when the addition reaches 300 or less print the... (8 Replies)
Discussion started by: bombcan
8 Replies

6. Shell Programming and Scripting

Adding numbers in a string

I am writing a bash script on ubuntu11.10 I have some string having numbers and letter and want to add all the numbers together For example 1s2d23f I want to perform 1 + 2 + 23 and store it in a variable (3 Replies)
Discussion started by: kristinu
3 Replies

7. Shell Programming and Scripting

Adding row of numbers

is there another way of doing the below: echo "7 3 8 2 2 1 3 83.4 8.2 4 8 73 90.5" | bc shell is bash. os is linux and sunos. bc seems to have an issue with long range of numbers (12 Replies)
Discussion started by: SkySmart
12 Replies

8. UNIX for Dummies Questions & Answers

Adding Column Of Numbers

Hello. Trying to add a column of numbers and combine the 1st and 2nd fields as uniq with the new total. This works to add the numbers but can't figure an easy was to combine the 1st and 2nd column as the list is very long. awk '{s+=$3} END {print s}' bird dog 300 bird dog 100 cat clown 200... (1 Reply)
Discussion started by: jimmyf
1 Replies

9. Shell Programming and Scripting

Adding (as in arithmetic) to numbers in columns in file, and writing new file with new numbers

Hi again. Sorry for all the questions — I've tried to do all this myself but I'm just not good enough yet, and the help I've received so far from bartus11 has been absolutely invaluable. Hopefully this will be the last bit of file manipulation I need to do. I have a file which is formatted as... (4 Replies)
Discussion started by: crunchgargoyle
4 Replies

10. Shell Programming and Scripting

Adding the squence numbers

Hi All, Could you please help me on this requirement. File data: A A A B B B i need the output like A1 A2 A3 B1 (3 Replies)
Discussion started by: bmk123
3 Replies
Locale::Codes::LangFam(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangFam(3pm)

NAME
Locale::Codes::LangFam - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangFam; $lext = code2langfam('apa'); # $lext gets 'Apache languages' $code = langfam2code('Apache languages'); # $code gets 'apa' @codes = all_langfam_codes(); @names = all_langfam_names(); DESCRIPTION
The "Locale::Codes::LangFam" module provides access to standard codes used for identifying language families, such as those as defined in ISO 639-5. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 639-5 language family codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language families. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langfam('apa','alpha'); $lext = code2langfam('apa',LOCALE_LANGFAM_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from ISO 639-5 such as 'apa' for Apache languages. This is the default code set. ROUTINES
code2langfam ( CODE [,CODESET] ) langfam2code ( NAME [,CODESET] ) langfam_code2code ( CODE ,CODESET ,CODESET2 ) all_langfam_codes ( [CODESET] ) all_langfam_names ( [CODESET] ) Locale::Codes::LangFam::rename_langfam ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangFam::add_langfam ( CODE ,NAME [,CODESET] ) Locale::Codes::LangFam::delete_langfam ( CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_alias ( NAME ,NEW_NAME ) Locale::Codes::LangFam::delete_langfam_alias ( NAME ) Locale::Codes::LangFam::rename_langfam_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::delete_langfam_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.loc.gov/standards/iso639-5/id.php ISO 639-5 . AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-11-04 Locale::Codes::LangFam(3pm)
All times are GMT -4. The time now is 01:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy