Czytam Porównanie dwóch plików przy użyciu Uniksa i Awk . To jest naprawdę interesujące. Przeczytałem i przetestowałem, ale nie rozumiem go całkowicie i używam w innych przypadkach.
Mam dwa pliki. file1
ma jedno pole, a drugie ma 16 pól. Chcę przeczytać elementy file
1 i porównać je z 3. polem file2
. Jeśli było dopasowanie dla każdego elementu, sumuję wartość pola 5 w file2
. Jako przykład:
plik 1
1
2
3
plik 2
2 2 2 1 2
3 6 1 2 4
4 1 1 2 3
6 3 3 3 4
Dla elementu 1 w file1
chcę dodać wartości w polu 5, file2
gdzie wartość pola 3 wynosi 1. I zrób to samo dla elementu 2 i 3 w file1
. Wynik dla 1 to (3 + 4 = 7), a dla 2 to 2, a dla 3 to 4.
Nie wiem, jak mam to napisać z awk.