![]() |
|
|
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. |
Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
|
||||
| Fio | Thread Starter | Fórum | Respostas | Última postagem |
| juntar dois arquivos | koti_rama | Programação Shell Script e | 5 | 08-05-2008 05:20 |
| Junte dois arquivos | koti_rama | Programação Shell Script e | 4 | 06-10-2008 07:15 |
| como juntar arquivos | jxh461 | UNIX para Dummies Perguntas & Respostas | 5 | 08-23-2007 08:11 |
| juntar ficheiros | mohan705 | Programação Shell Script e | 3 | 03-15-2007 06:51 |
| Acesse Ficheiros | choppas | Programação Shell Script e | 2 | 10-18-2006 11:03 |
![]() |
|
|
Linkback | Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Esquerda aderir em arquivos usando awk
Citação:
Citação:
Citação:
Código:
nawk 'NR==FNR{a[$1];next} {if($1 in a) print $1,"Found" else print}' OFS="," File_B File_A
O código acima não está funcionando a ajuda é apreciada |
|
||||
|
bem essa foi fácil, você está em falta sobre a sintaxe
nawk 'NR \u003d\u003d FNR uma ([$ 1]; próxima) (if ($ 1 em um) print $ 1, "foi encontrado";) print' OFS \u003d "," File_B File_A ----- ----- Post Update amostra de saída bash-nawk $ 3,00 'NR \u003d\u003d FNR uma ([$ 1]; próxima) (if ($ 1 em um) print $ 1, "foi encontrado";) print' OFS \u003d "," File_B File_A NY, Encontrado NY NJ, Encontrado NJ PA CA, Encontrado CA VA, Encontrado VA TN |
|
||||
|
Citação:
Esta não é a saída estou procurando. veja os resultados |
|
||||
|
se você tiver o Python, uma alternativa Código:
#!/usr/bin/env python
file2=[i.split()[0] for i in open("file2").read().split("\n")]
for line in open("file1"):
line=line.strip().split()
if line[0] in file2:
print line[0]," found"
else:
print line[0],","
saída Código:
# ./test.py NY found NJ found PA , CA found VA found TN , |
|
|||||
|
Citação:
Código:
perl -ne 'BEGIN{open(F,"fileb"); while(<F>){split;$found{$_[0]}="Found"} close(F)} {chomp; print "$_,$found{$_}\n"}' filea
Teste: Código:
$
$ cat filea
NY
NJ
PA
CA
VA
TN
$
$ cat fileb
NY hello
NJ 3
CA 1
VA 5
$
$ perl -ne 'BEGIN{open(F,"fileb"); while(<F>){split;$found{$_[0]}="Found"} close(F)} {chomp; print "$_,$found{$_}\n"}' filea
NY,Found
NJ,Found
PA,
CA,Found
VA,Found
TN,
$
tyler_durden |
![]() |
| Marcadores |
| Thread Tools | Pesquisar este Thread |
| Display Modes | Esta taxa Thread |
|
|