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

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

Re: [shell-script] Re: Desafio shellscript - Cálculo de milivolts por me


From: Raul Libório
Subject: Re: [shell-script] Re: Desafio shellscript - Cálculo de milivolts por metro
Date: Sat, 20 Aug 2016 20:45:59 -0300

Perfeito Itamar!

Eu tive esse problema a 4 anos atrás, e guardei o script que resolveu esse problema:
###
#!/bin/bash
ORIGINAL="1.TXT"
FILE="out.txt"
MILIVOLT=0
sed '/Logging/d;/Max/d;' ${ORIGINAL} > ${FILE}
for VALOR in $(cat ${FILE}) ; do
if [[ "${VALOR}" == *mV/m ]]; then
VALOR=$( echo ${VALOR} | tr -d 'V/m' )
VALOR=$( bc <<< "scale=3; ${VALOR} / 1000" )
MILIVOLT=$( bc <<< "${VALOR} + ${MILIVOLT}" )
else
VALOR=$( echo ${VALOR} | tr -d 'MmV/' )
MILIVOLT=$( bc <<< "${VALOR} + ${MILIVOLT}" )
fi
done
echo "Arquivo $(basename $0) possui ${MILIVOLT}mV/m"

###

Eu fico até com vergonha depois de seu one-liner destruidor, mas foi o que fiz na época :D
Engraçado é que o meu dá 450.606mV/m, e o seu deu 450607mV/m.



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-20 19:21 GMT-03:00 address@hidden [shell-script] <address@hidden>:
 

Caro Raul

Como aprecio awk em especial:

awk '/[0-9]V/ {$1*=1000}; {soma+=$1}; END {print soma "mV/m"}' arquivo

[]'s
Itamar



reply via email to

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