一致する列と一致しない列の値を追加し、他のファイルに書き込む

一致する列と一致しない列の値を追加し、他のファイルに書き込む
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

おすすめ記事