<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Unix scripts: how to sum numbers up</title>
	<atom:link href="http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/</link>
	<description>Learn UNIX</description>
	<lastBuildDate>Thu, 26 Jan 2012 23:00:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Emil</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-6934</link>
		<dc:creator>Emil</dc:creator>
		<pubDate>Tue, 21 Dec 2010 18:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-6934</guid>
		<description>Hello

I&#039;m trying to sum a field in a &#124; delimited file but not receiving the correct value.  Not sure how I&#039;m getting e+06. Please help
cat file.TXT &#124;awk &#039;FS = &quot;&#124;&quot; { sum += $12 } END { print sum }&#039;&#124;xargs -n1&#124;while read sum ;do aa=&#039;$&#039;$sum ;done
echo $aa
7.60411e+06

Thank you</description>
		<content:encoded><![CDATA[<p>Hello</p>
<p>I'm trying to sum a field in a | delimited file but not receiving the correct value.  Not sure how I'm getting e+06. Please help<br />
cat file.TXT |awk 'FS = "|" { sum += $12 } END { print sum }'|xargs -n1|while read sum ;do aa='$'$sum ;done<br />
echo $aa<br />
7.60411e+06</p>
<p>Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeff</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-6923</link>
		<dc:creator>jeff</dc:creator>
		<pubDate>Sun, 12 Dec 2010 17:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-6923</guid>
		<description>Neeraj Batra, you would need double quotes instead of single quotes to allow the shell to interpret the variables.</description>
		<content:encoded><![CDATA[<p>Neeraj Batra, you would need double quotes instead of single quotes to allow the shell to interpret the variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neeraj Batra</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-6909</link>
		<dc:creator>Neeraj Batra</dc:creator>
		<pubDate>Mon, 08 Nov 2010 07:42:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-6909</guid>
		<description>Hi Pete

Thanks for your response, But the problem is that in below example

echo &#039;scale=25;57/43′ &#124; bc

Values 57 and 43 are in variables in my script

i.e. 

a=57
b=43
echo &#039;scale=25;$a/$b′ &#124; bc

Above does not work :(

Plz help

Rgds
Neeraj Batra</description>
		<content:encoded><![CDATA[<p>Hi Pete</p>
<p>Thanks for your response, But the problem is that in below example</p>
<p>echo 'scale=25;57/43′ | bc</p>
<p>Values 57 and 43 are in variables in my script</p>
<p>i.e. </p>
<p>a=57<br />
b=43<br />
echo 'scale=25;$a/$b′ | bc</p>
<p>Above does not work <img src='http://unixtutorial.s3.amazonaws.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Plz help</p>
<p>Rgds<br />
Neeraj Batra</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeff</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-6837</link>
		<dc:creator>jeff</dc:creator>
		<pubDate>Wed, 24 Mar 2010 17:20:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-6837</guid>
		<description>You can make your code tighter in ksh and bash:

SUM+=$NUM

instead of

SUM=$(($SUM + $NUM))

Also, you can use an awk one-liner instead of a while loop:

for i in 1 2 3 4 5; do echo $i; done &#124;  awk &#039;{s+=$1} END  {print s}&#039;

or

cat &#124; awk &#039;{s+=$1} END {print s}&#039;
1
2
3
4
5
^d
15 (result)</description>
		<content:encoded><![CDATA[<p>You can make your code tighter in ksh and bash:</p>
<p>SUM+=$NUM</p>
<p>instead of</p>
<p>SUM=$(($SUM + $NUM))</p>
<p>Also, you can use an awk one-liner instead of a while loop:</p>
<p>for i in 1 2 3 4 5; do echo $i; done |  awk '{s+=$1} END  {print s}'</p>
<p>or</p>
<p>cat | awk '{s+=$1} END {print s}'<br />
1<br />
2<br />
3<br />
4<br />
5<br />
^d<br />
15 (result)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-5720</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Wed, 05 Aug 2009 19:13:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-5720</guid>
		<description>Hello Ankan,
you need to use &quot;scale&quot; option from bc:
echo &#039;scale=25;57/43&#039; &#124; bc

Scale controls the number of decimal points.  Not sure if scale is an option, command or what not... but that&#039;s your answer.  

Regards,
Pete</description>
		<content:encoded><![CDATA[<p>Hello Ankan,<br />
you need to use "scale" option from bc:<br />
echo 'scale=25;57/43' | bc</p>
<p>Scale controls the number of decimal points.  Not sure if scale is an option, command or what not&#8230; but that's your answer.  </p>
<p>Regards,<br />
Pete</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Floating point calculations in Unix scripts &#8212; UNIX Tutorial: Learn UNIX</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-5045</link>
		<dc:creator>Floating point calculations in Unix scripts &#8212; UNIX Tutorial: Learn UNIX</dc:creator>
		<pubDate>Thu, 18 Jun 2009 12:12:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-5045</guid>
		<description>[...] Summing numbers up in Unix scripts [...]</description>
		<content:encoded><![CDATA[<p>[...] Summing numbers up in Unix scripts [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ankan</title>
		<link>http://www.unixtutorial.org/2009/02/unix-scripts-how-to-sum-numbers-up/comment-page-1/#comment-4976</link>
		<dc:creator>Ankan</dc:creator>
		<pubDate>Mon, 15 Jun 2009 13:35:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.unixtutorial.org/?p=465#comment-4976</guid>
		<description>Hello,

   Can you please provide the following codes:

1. I divide 20 /6 . The answer id now 3. It sould be 3.33
2. How to do  10.222 + 1.1 = 11.322

Thanks in advance. :-)</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>   Can you please provide the following codes:</p>
<p>1. I divide 20 /6 . The answer id now 3. It sould be 3.33<br />
2. How to do  10.222 + 1.1 = 11.322</p>
<p>Thanks in advance. <img src='http://unixtutorial.s3.amazonaws.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 3/13 queries in 0.014 seconds using disk: basic
Object Caching 373/376 objects using disk: basic
Content Delivery Network via Amazon Web Services: S3: unixtutorial.s3.amazonaws.com

Served from: www.unixtutorial.org @ 2012-02-08 01:05:10 -->
