![]() |
Olá e boas-vindas de Estados Unidos para o UNIX e Linux Forum! Obrigado por visitar e fazer parte da nossa comunidade global.
|
|
google unix.com
|
|||||||
| Fóruns | Registar | Fórum Regimento | Ligações | Álbuns | FAQ | Lista deputados | Calendário | Pesquisa | Today's Posts | Mark Forums Read |
| 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. |
![]() |
|
|
Linkback | Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
|
![]() |
| Marcadores |
| Thread Tools | Pesquisar este Thread |
| Display Modes | Esta taxa Thread |
|
|