Caro Raul
file.txt = 2.000.000 linhas
Se você usa o sed mais tr, quando uma linha non te numero você obtê un
error.
***@elnegre:~$ time echo "scale=10; $(sed 's/[Aa-zZ]//g;s/ //g'
file.txt | tr '\n' '+') 0" | bc
(standard_in) 1: syntax error
real 0m14.987s
user 0m13.460s
sys 0m1.432s
A melhor opção e:
*/When you use sed & tr, if one line don't have numbers, you have error./*
/*Better option is:*/
echo "scale=10; $(sed 's/[Aa-zZ]//g;s/ //g' file.txt | paste -s -d+) 0" | bc
Outro problema com o meu sed, e que arquivos com mais de 2.000.000 de
linhas tem error.
*/My sed can not file more than 2,000,000 lines./*
S.O = UBUNTU 14.04
Pere
***@gmail.com <mailto:***@gmail.com>
<http://www.imatge.com/>
------------------------------------
AVIS LEGAL
Nota de confidencialitat: Aquest missatge podria contenir missatges
d'empresa i altre informació confidencial tutelada per les lleis de
Europea i altres estats, Si VostÚ el rep per error o sense ser una de
les persones esmenades a la capçalera, haurà de destruir-lo sense
copiar-lo ni revelar-l'ho o qualsevol altre acció relacionada amb el
contingut del missatge i notificar-ho per correu electrònic a l'emissor
del missatge.
Les persones o entitats que incompleixin els deures de confidencialitat
podran ésser perseguides davant dels Tribunals de JustÃcia sota l'empar
de la legislació civil, penal i administrativa nacional i internacional.
Gracies per la seva cooperació.
------------------------------------
LEGAL NOTICE
Confidentiality notice: This mail may include business and other
confidential information protected under the laws of and other
territories. if you are not one of the intended recipients of the
message, you are legally obliged to delete the message content.
Furthermore, you are kindly requested to report immediately the incident
to the sender.
Breach of confidentiality duties is a serious criminal offence in and
other territories. Offenders shall be legally prosecuted worldwide.
Thank you for your cooperation.
Post by Raul Libório ***@gmail.com [shell-script]Carlos Peixoto, usando a mesma lógica que o Júlio colocou no desafio
$ 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
Tenho um arquivo com números reais, sendo somente um por linha.
Como faço para extrair o total?
1.23 sdfa
4.55vvvv
sfgweg9.23
sdfgs 4.78 gh
Grato a todos