|
Home > Archive > Unix Programming > January 2007 > Reading from a loop
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Reading from a loop
|
|
| chaitu 2007-01-17, 1:17 pm |
| Hi,
I have a file as folows.
2400000
2399680
1896288
503392
And i am trying to read the numbers from this file and perform the
required calculations. I mean i want to divide (503392/2400000). How do
i do that?
Thanks in advance,
Krish
| |
| Pascal Bourguignon 2007-01-17, 1:17 pm |
| "chaitu" <chaituonweb@gmail.com> writes:
> I have a file as folows.
>
> 2400000
> 2399680
> 1896288
> 503392
>
> And i am trying to read the numbers from this file and perform the
> required calculations. I mean i want to divide (503392/2400000). How do
> i do that?
>
> Thanks in advance,
I don't see the relationship with loops.
(with-input-from-string (*standard-input* "
2400000
2399680
1896288
503392
")
(let ((divisor (read)) (dividend (progn (read) (read) (read))))
(/ dividend divisor)))
--> 15731/75000
--
__Pascal Bourguignon__ http://www.informatimago.com/
PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
| |
| Chris F.A. Johnson 2007-01-17, 7:28 pm |
| On 2007-01-17, chaitu wrote:
> Hi,
>
> I have a file as folows.
>
> 2400000
> 2399680
> 1896288
> 503392
>
> And i am trying to read the numbers from this file and perform the
> required calculations. I mean i want to divide (503392/2400000). How do
> i do that?
Use a loop that reads the file one line at a time. For example,
using the shell:
while read num
do
echo $(( $num / 2400000 ))
done < /path/to/file
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Logan Shaw 2007-01-17, 7:28 pm |
| chaitu wrote:
> I have a file as folows.
>
> 2400000
> 2399680
> 1896288
> 503392
>
> And i am trying to read the numbers from this file and perform the
> required calculations. I mean i want to divide (503392/2400000). How do
> i do that?
Here's a simple way to do that using the shell:
expr `tail -1 myfile` / `head -1 myfile`
I suspect you want something different than that, but that fits your
description, so maybe you should be more specific. :-)
- Logan
|
|
|
|
|