πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #8730

Re: suma en bash

#8730
From: ale
Date: Thu, 10 Oct 2002 04:33
47 lines
1629 bytes
Esteban Navarro <scandisk@able.es> wrote in message news:<mg9tna.81a.ln@127.0.0.1>...-
> 
> 
> Estoy intentando crear un script en bash que me sume los numeros de un 
> fichero: ej.
> 
> 12,67
> 14,78
> 45,90
> 56,34
> ...
> 
> οΏ½Es posible?
> 


# suma numeros enteros

suma=0
for num in `cat fichero`
    do
      ((suma+=num))
    done

echo "$suma"


# suma numeros de punto flotante (decimal separado por un punto)

suma=0
for num in `cat fichero`
     do
        suma=$(echo "scale=2; $suma+$num" | bc)
     done

echo "$suma"


# suma numeros de punto flotante (decimal separado por una coma)

suma=0
for num in `sed 's/,/./g' fichero`
     do
        suma=$(echo "scale=2; $suma+$num" | bc)
     done

echo `echo "$suma" | sed 's/\./,/'`
Technical Details
Message-ID: <f817ee1f.0210092033.7fe1b2a8@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mail
References: <mg9tna.81a.ln@127.0.0.1>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,56cc30fda95ab037
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2002-10-09 21:33:33 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!postnews1.google.com!not-for-mail
From: anr@freeshell.org (ale)
Newsgroups: es.comp.os.linux.programacion
Subject: Re: suma en bash
Date: 9 Oct 2002 21:33:33 -0700
Organization: http://groups.google.com/
Lines: 47
Message-ID: <f817ee1f.0210092033.7fe1b2a8@posting.google.com>
References: <mg9tna.81a.ln@127.0.0.1>
NNTP-Posting-Host: 209.13.179.192
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1034224413 12316 127.0.0.1 (10 Oct 2002 04:33:33 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 10 Oct 2002 04:33:33 GMT