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: Gmail
Subject: Re: [shell-script] Somar números de um arquivo
Date: Tue, 23 Aug 2016 00:57:55 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

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@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

address@hidden




------------------------------------

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.



El 22/08/16 a les 19:28, Raul Libório address@hidden [shell-script] ha escrit:
 
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>:
 
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]