[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [shell-script] FW: mais uma de awk ( Formatar numeros )
From: |
Fábio Batista |
Subject: |
Re: [shell-script] FW: mais uma de awk ( Formatar numeros ) |
Date: |
Fri, 24 Jun 2005 12:48:25 -0300 |
Eu acho a solução com sed mais elegante:
[fabio@elefante testes]$ cat valores.txt
00000001534
00000025682
00000000150
00004152358
00000000023
12345678901
[fabio@elefante testes]$ cat valores.txt | sed -r
's/^[0]*([0-9]+)([0-9]{2})/R$ \1,\2/'
R$ 15,34
R$ 256,82
R$ 1,50
R$ 41523,58
R$ 0,23
R$ 123456789,01
--
Fábio David Batista
address@hidden
http://nerd-o-matic.blogspot.com
On 6/23/05, MrBiTs <address@hidden> wrote:
> Mais uma contribuição do nosso amigo moderado Miranda:
>
> [miranda@guitar tmp]$ cat valores
> 00000001534
> 00000025682
> 00000000150
> 00004152358
> 00000000023
> 12345678901
> [miranda@guitar tmp]$ cat cmd.awk
> {TAM=length($0);
> DEC=substr($0,TAM-1);
> INT=substr($0,0,TAM-2);
> printf"R$%d,%s\n",INT,DEC;}
> [miranda@guitar tmp]$ awk -f cmd.awk valores
> R$15,34
> R$256,82
> R$1,50
> R$41523,58
> R$0,23
> R$123456789,01