[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE)
From: |
Fábio Batista |
Subject: |
Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE) |
Date: |
Mon, 4 Jul 2005 19:21:20 -0300 |
Com bash é barbada:
[fabio@elefante testes]$ cat tempos.txt
ROTINA1 01:31:44
ROTINA2 01:21:24
ROTINA3 05:55:03
ROTINA4 11:41:44
ROTINA5 55:21:23
ROTINA6 03:31:24
ROTINA7 01:07:41
[fabio@elefante testes]$ cat tempos.sh
#!/bin/bash
# vim:ts=2:
totalh=0
totalm=0
totals=0
IFS=":"
while read h m s
do
echo "h: $h m: $m s: $s"
totalh=$((totalh + h))
totalm=$((totalm + m))
totals=$((totals + s))
done < <( sed -r 's/^\S+\s+//' tempos.txt )
while [ $totals -gt 60 ]
do
totalm=$((totalm + 1))
totals=$((totalh - 60))
done
while [ $totalm -gt 60 ]
do
totalh=$((totalh + 1))
totalm=$((totalm - 60))
done
echo "total: h: $totalh m: $totalm s: $totals"
[fabio@elefante testes]$ bash tempos.sh
h: 01 m: 31 s: 44
h: 01 m: 21 s: 24
h: 05 m: 55 s: 03
h: 11 m: 41 s: 44
h: 55 m: 21 s: 23
h: 03 m: 31 s: 24
h: 01 m: 07 s: 41
total: h: 80 m: 28 s: 17
--
Fábio David Batista
address@hidden
http://nerd-o-matic.blogspot.com
On 7/4/05, Jorge Pereira <address@hidden> wrote:
> Olá Amigos da Lista,
> Estou com uma Bronca muito seria e sei que se deus quiser algum
> abençoado vai me ajudar a resolver está bronca.
> vamos lá.
>
> 1) eu tenho um programa que me retorna as tais colunas, exemplo.
>
> = > Programa XYZ
>
> ROTINA1 01:31:44
> ROTINA2 01:21:24
> ROTINA3 05:55:03
> ROTINA4 11:41:44
> ROTINA5 55:21:23
> ROTINA6 03:31:24
> ROTINA7 01:07:41
>
> 2) O que eu preciso, tipo! preciso que ele pegue estes dados e gere um
> calculo tipo.
>
>
> O Programa (XYZ) teve uma media de X horas e Y minutos e Z Segundos, ou
> algo parecido
>
> 22h:41m:03s
>
> ou
>
> 1d:12m:44s
>
> OBS: Se alguem puder me ajudar, ficaria muito grato com este calculo...
> acho que o ideal seria utilizar o AWK, mais não consegue abstrair o
> calculo
> perfeito para tal situação.
>
> Um Abraço a todos
- calcular hora (essa e bronca, totalmente HARDCORE), Jorge Pereira, 2005/07/04
- Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE),
Fábio Batista <=
- Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE), Fábio Batista, 2005/07/04
- Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE), Fábio Batista, 2005/07/04
- Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE), Jorge Pereira, 2005/07/04
- Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE), Fábio Batista, 2005/07/04
- Re: [shell-script] calcular hora (essa e bronca, totalmente HARDCORE), Jorge Pereira, 2005/07/04
- "This", "me" ou algo equivalente, Giovanni Almeida, 2005/07/11
- RE: [shell-script] "This", "me" ou algo equivalente, MrBiTs, 2005/07/11
- Re: [shell-script] "This", "me" ou algo equivalente, Tiago Peczenyj, 2005/07/11
- Re: [shell-script] "This", "me" ou algo equivalente, Daniel ® Antunes, 2005/07/11
- Re: [shell-script] "This", "me" ou algo equivalente, Emerson Domingues Souto, 2005/07/11