shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Somar números de um arquivo


From: Fredi Rolf Bieging
Subject: Re: [shell-script] Somar números de um arquivo
Date: Mon, 22 Aug 2016 15:24:45 -0300

Usando o grep pra pegar os números e o paste pra botar o + entre eles:

grep -Eo '[0-9]+\.?[0-9]*' arquivo | paste -s -d+ | bc

On Mon, Aug 22, 2016 at 2:28 PM, Raul Libório address@hidden [shell-script] <address@hidden> wrote:
 

Carlos Peixoto, usando a mesma lógica que o Júlio colocou no desafio anterior, respondo o seu:

$ cat file.txt
1.23 sdfa
4.55vvvv
sfgweg9.23
sdfgs 4.78 gh

$ echo "scale=3; $(sed 's/[Aa-zZ]//g;s/ //g' file.txt | tr '\n' '+') 0" | bc
19.79


Abraços

Raul Libório
http://rauhmaru.blogspot.com/
openSUSE Member | Linux User #4444581

/etc/httpd/conf.d/ssl.conf:7
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.

2016-08-22 13:31 GMT-03:00 Carlos Peixoto Costa Peixoto address@hidden [shell-script] <address@hidden.br>:
 

Tenho um arquivo com números reais, sendo somente um por linha. Como faço para extrair o total?

Ex:
1.23 sdfa
4.55vvvv
sfgweg9.23
sdfgs 4.78 gh

Grato a todos




reply via email to

[Prev in Thread] Current Thread [Next in Thread]