![일치하는 열과 일치하지 않는 열의 값을 추가하고 다른 파일에 쓰기](https://linux55.com/image/164027/%EC%9D%BC%EC%B9%98%ED%95%98%EB%8A%94%20%EC%97%B4%EA%B3%BC%20%EC%9D%BC%EC%B9%98%ED%95%98%EC%A7%80%20%EC%95%8A%EB%8A%94%20%EC%97%B4%EC%9D%98%20%EA%B0%92%EC%9D%84%20%EC%B6%94%EA%B0%80%ED%95%98%EA%B3%A0%20%EB%8B%A4%EB%A5%B8%20%ED%8C%8C%EC%9D%BC%EC%97%90%20%EC%93%B0%EA%B8%B0.png)
DR_CNDAOFSZAPZP_GPFS_VOL.0 139264
DR_CNDAOFSZAPZP_GPFS_VOL.1 15657
DR_CNDAOFSZAPZP_GPFS_VOL.0 139264
DR_CNDAOFSZAPZP_GPFS_VOL.1 156579
DR_CNDAOFSZAPZP_GPFS_VOL.2 156579
DR_CNDAOFSZAPZP_GPFS_VOL.3 156579
DR_CNDAOFSZAPZP_GPFS_VOL.5 172236
출력 파일 1(일치하는 서버 포함)
Server1 Vzise
DR_CNDAOFSZAPZP_GPFS_VOL.0 278528
DR_CNDAOFSZAPZP_GPFS_VOL.1 172236
출력 파일 2(일치하는 서버 없음)
DR_CNDAOFSZAPZP_GPFS_VOL.2 156579
DR_CNDAOFSZAPZP_GPFS_VOL.3 156579
DR_CNDAOFSZAPZP_GPFS_VOL.5 172236
답변1
$ awk '{Arr[$1]+=$2;Count[$1]++}END{for(i in Arr){if(Count[i]>1){print i,Arr[i] > "out_1"}else{print i,Arr[i] > "out_2"}}}' file1
$ ls -lrt
total 12
-rw-r--r--. 1 xxxxxxxxxxxxx yyyyyyyyyyyyyyyy 272 Nov 14 15:45 file1
-rw-r--r--. 1 xxxxxxxxxxxxx yyyyyyyyyyyyyyyy 102 Nov 14 15:48 out_2
-rw-r--r--. 1 xxxxxxxxxxxxx yyyyyyyyyyyyyyyy 68 Nov 14 15:48 out_1
$ cat out_1
DR_CNDAOFSZAPZP_GPFS_VOL.0 278528
DR_CNDAOFSZAPZP_GPFS_VOL.1 172236
$ cat out_2
DR_CNDAOFSZAPZP_GPFS_VOL.2 156579
DR_CNDAOFSZAPZP_GPFS_VOL.3 156579
DR_CNDAOFSZAPZP_GPFS_VOL.5 172236