The UNIX and Linux Forums  
Olá e boas-vindas de Estados Unidos para o UNIX e Linux Forum! Obrigado por visitar e fazer parte da nossa comunidade global.

Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
google unix.com



Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
Linkback Thread Tools Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-17-2008
jkl_jkl jkl_jkl is offline
Usuário
  
 

Join Date: Aug 2007
Lugares: 46
awk ajudar

Oi tudo,

Código:
Input file: file.txt
_____________________

7789 0
3445 1
7789 1
1223 0
4567 0
7789 0
7789 0
1212 1
3445 0
7789 1
3445 1


How can I get the output as:

<number> <no_0_entries> <no_1_entries>

i.e.

7789 3 2
3445 1 2
1223 1 0
4567 1 0
1212 0 1
Não tenho sorte na resolução deste, por favor ajude. Obrigado.
  #2 (permalink)  
Old 07-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Localização: Sydney, Austrália
Posts: 1.009
O que você tentou?
  #3 (permalink)  
Old 07-17-2008
jkl_jkl jkl_jkl is offline
Usuário
  
 

Join Date: Aug 2007
Lugares: 46
Tentei até este

Código:
$ awk '$2==0' file.txt > file.txt.0
$ awk '$2==1' file.txt > file.txt.1

$ cat file.txt.0
7789 0
1223 0
4567 0
7789 0
7789 0
3445 0

$ cat file.txt.1
3445 1
7789 1
1212 1
7789 1
3445 1

<0 entries>
$ awk '{count[$1]++}END{for(j in count) print j,count[j]}' file.txt.0
1223 1
4567 1
7789 3
3445 1

<1 entries>
$ awk '{count[$1]++}END{for(j in count) print j,count[j]}' file.txt.1
7789 2
3445 2
1212 1
  #4 (permalink)  
Old 07-17-2008
jkl_jkl jkl_jkl is offline
Usuário
  
 

Join Date: Aug 2007
Lugares: 46
Alguém poderia me ajudar nesta por favor. Obrigado.
  #5 (permalink)  
Old 07-17-2008
jkl_jkl jkl_jkl is offline
Usuário
  
 

Join Date: Aug 2007
Lugares: 46
Como alcançar os req saída, por favor guia.
  #6 (permalink)  
Old 07-17-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Usuário
  
 

Join Date: Sep 2006
Mensagens: 2.530
u pode tentar criar array com US $ 1 e $ 2 como a chave.
  #7 (permalink)  
Old 07-17-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Usuário
  
 

Join Date: Apr 2004
Location: Bordeaux, França
Mensagens: 1.420
Uma possível solução, com awk :
Código:
awk '
{
   numbers[$1]++;
   zero[$1] += ($2 == 0 ? 1 : 0);
    one[$1] += ($2 == 1 ? 1 : 0);
}
END {
   for (i in numbers) {
      print i,zero[i],one[i]
   }
}' inputfile
Jean-Pierre.
Closed Thread

Marcadores

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 10:22.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0