ファイル1:
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 283 F30109_THK_T0_CFPUR0701_DS005 2022-06-02 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 284 F30109_THK_T0_CFPUR0701_DS005 2022-06-03 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 285 F30109_THK_T0_CFPUR0701_DS005 2022-06-04 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 286 F30109_THK_T0_CFPUR0701_DS005 2022-06-05 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 287 F30109_THK_T0_CFPUR0701_DS005 2022-06-06 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 288 F30109_THK_T0_CFPUR0701_DS005 2022-06-07 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS006 hostgroups-1d1w 282 F30109_THK_T0_CFPUR0701_DS006 2022-06-01 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 283 F30109_THK_T0_CFPUR0702_DS006 2022-06-02 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 284 F30109_THK_T0_CFPUR0702_DS006 2022-06-03 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 285 F30109_THK_T0_CFPUR0702_DS006 2022-06-04 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 286 F30109_THK_T0_CFPUR0702_DS006 2022-06-05 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 287 F30109_THK_T0_CFPUR0702_DS006 2022-06-06 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS006 hostgroups-1d1w 288 F30109_THK_T0_CFPUR0703_DS006 2022-06-07 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 282 F30109_THK_T0_CFPUR0703_DS007 2022-06-01 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 283 F30109_THK_T0_CFPUR0703_DS007 2022-06-02 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 284 F30109_THK_T0_CFPUR0703_DS007 2022-06-03 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 285 F30109_THK_T0_CFPUR0703_DS007 2022-06-04 00:00:00
ファイル2:
cfpur0701 hostgroups-1d1w 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0701 hostgroups-1d1w 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0701 hostgroups-1d1w 2022-06-04 00:00:00 2022-06-11 00:00:00
cfpur0701 hostgroups-1d1w 2022-06-05 00:00:00 2022-06-12 00:00:00
cfpur0701 hostgroups-1d1w 2022-06-06 00:00:00 2022-06-13 00:00:00
cfpur0701 hostgroups-1d1w 2022-06-07 00:00:00 2022-06-14 00:00:00
cfpur0701 hostgroups-1d1w 2022-06-01 00:00:00 2022-06-08 00:00:00
cfpur0702 hostgroups-1d1w 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0702 hostgroups-1d1w 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0702 hostgroups-1d1w 2022-06-04 00:00:00 2022-06-11 00:00:00
cfpur0702 hostgroups-1d1w 2022-06-05 00:00:00 2022-06-12 00:00:00
cfpur0702 hostgroups-1d1w 2022-06-06 00:00:00 2022-06-13 00:00:00
cfpur0702 hostgroups-1d1w 2022-06-07 00:00:00 2022-06-14 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-01 00:00:00 2022-06-08 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-04 00:00:00 2022-06-11 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-05 00:00:00 2022-06-12 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-06 00:00:00 2022-06-13 00:00:00
cfpur0703 hostgroups-1d1w 2022-06-07 00:00:00 2022-06-14 00:00:00
cfpur0801 hostgroups-1d1w 2022-06-01 00:00:00 2022-06-08 00:00:00
cfpur0801 hostgroups-1d1w 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0801 hostgroups-1d1w 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0801 hostgroups-1d1w 2022-06-04 00:00:00 2022-06-11 00:00:00
希望の出力:
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 283 F30109_THK_T0_CFPUR0701_DS005 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 284 F30109_THK_T0_CFPUR0701_DS005 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 285 F30109_THK_T0_CFPUR0701_DS005 2022-06-04 00:00:00 2022-06-11 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 286 F30109_THK_T0_CFPUR0701_DS005 2022-06-05 00:00:00 2022-06-12 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 287 F30109_THK_T0_CFPUR0701_DS005 2022-06-06 00:00:00 2022-06-13 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS005 hostgroups-1d1w 288 F30109_THK_T0_CFPUR0701_DS005 2022-06-07 00:00:00 2022-06-14 00:00:00
cfpur0701 Pgroup F30109 cf3010922 F30109_FPUR0701_PRD03E_DS006 hostgroups-1d1w 282 F30109_THK_T0_CFPUR0701_DS006 2022-06-01 00:00:00 2022-06-08 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 283 F30109_THK_T0_CFPUR0702_DS006 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 284 F30109_THK_T0_CFPUR0702_DS006 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 285 F30109_THK_T0_CFPUR0702_DS006 2022-06-04 00:00:00 2022-06-11 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 286 F30109_THK_T0_CFPUR0702_DS006 2022-06-05 00:00:00 2022-06-12 00:00:00
cfpur0702 Pgroup F30109 cf3010922 F30109_FPUR0702_PRD03E_DS006 hostgroups-1d1w 287 F30109_THK_T0_CFPUR0702_DS006 2022-06-06 00:00:00 2022-06-13 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS006 hostgroups-1d1w 288 F30109_THK_T0_CFPUR0703_DS006 2022-06-07 00:00:00 2022-06-14 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 282 F30109_THK_T0_CFPUR0703_DS007 2022-06-01 00:00:00 2022-06-08 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 283 F30109_THK_T0_CFPUR0703_DS007 2022-06-02 00:00:00 2022-06-09 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 284 F30109_THK_T0_CFPUR0703_DS007 2022-06-03 00:00:00 2022-06-10 00:00:00
cfpur0703 Pgroup F30109 cf3010922 F30109_FPUR0703_PRD03E_DS007 hostgroups-1d1w 285 F30109_THK_T0_CFPUR0703_DS007 2022-06-04 00:00:00 2022-06-11 00:00:00
file1 の行数は常に file2 の行数よりも大きくなります。以下を行う必要があります。
ファイル1とファイル2の列1を比較し、一致する場合は、ファイル1の列6をファイル2の列2と比較し、最後にファイル1の列9をファイル2の列2と比較します。比較のために列3。3つの条件がすべて満たされたら、file2からタイムスタンプ(列5と6)を取得し、file1に追加して出力ファイルを生成します。
いくつかのバージョンのawkを試してみましたが、NR==FNR
多くの進歩はありませんでした。
答え1
awk 'FNR==NR{map[$1,$2,$3,$4] = $5 FS $6; next}
($1,$6,$9,$10) in map {print $0,map[$1,$6,$9,$10]}' file2 file1
(file1の最後の2つの列と一致させるために)必要だと思ったので、マッピングに日付と時刻のフィールドを使用しました。
最初のファイルパス(FNR==NR
)では、共通配列に追加するフィールド(最後の2つ)が格納され、最初の4つはハッシュとして使用されます。next
最初のファイルのすべての行に対して残りのコードを実行しないことが必要です。
2番目のファイルの場合は、配列値を追加し、選択したフィールドが既存の配列ハッシュを形成する場合にのみ行を印刷します。