HI我還有一個讓你大腦混亂的人;我有2個文本文件,我需要找到行中的差異,並寫入第三個文件,但在相同的分區下。比較兩個文件,並將第三個文件中的不同記錄移動到
例如:
文件:1
==================== ============================== ======================== ==============================
JOB STATUS - Activity
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_audt_trxn_refnc_uld.ksh ,20110317 ,Mar 17,04:41:49 ,Mar 17,04:43 ,SUCCESS
d_isso_actvy_log_uld_cln.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_voy_svc_sesn_ctm.ksh , ,~~~ UPSTREAM PENDING/YET TO START ~~~ , ,
d_svc_evt_sumry_ld_ctm.ksh , ,~~~ UPSTREAM PENDING/YET TO START ~~~ , ,
==================== ============================== ======================== ==============================
JOB STATUS - Schedule
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_audt_trxn_refnc_uld.ksh ,20110317 ,Mar 17,04:41:49 ,Mar 17,04:43 ,SUCCESS
d_isso_actvy_log_uld_cln.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_voy_svc_sesn_ctm.ksh , ,~~~ UPSTREAM PENDING/YET TO START ~~~ , ,
d_svc_evt_sumry_ld_ctm.ksh , ,~~~ UPSTREAM PENDING/YET TO START ~~~ , ,
==================== ============================== ======================== ==============================
JOB STATUS - Linkage
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_audt_trxn_refnc_uld.ksh ,20110317 ,Mar 17,04:41:49 ,Mar 17,04:43 ,SUCCESS
d_isso_actvy_log_uld_cln.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_voy_svc_sesn_ctm.ksh , ,~~~ UPSTREAM PENDING/YET TO START ~~~ , ,
d_svc_evt_sumry_ld_ctm.ksh , ,~~~ UPSTREAM PENDING/YET TO START ~~~ , ,
#############################################################################################################################
文件:2
==================== ============================== ======================== ==============================
JOB STATUS - Activity
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_audt_trxn_refnc_uld.ksh ,20110317 ,Mar 17,04:41:49 ,Mar 17,04:43 ,SUCCESS
d_isso_actvy_log_uld_cln.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
==================== ============================== ======================== ==============================
JOB STATUS - Schedule
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_audt_trxn_refnc_uld.ksh ,20110317 ,Mar 17,04:41:49 ,Mar 17,04:43 ,SUCCESS
d_isso_actvy_log_uld_cln.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
==================== ============================== ======================== ==============================
JOB STATUS - Linkage
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_audt_trxn_refnc_uld.ksh ,20110317 ,Mar 17,04:41:49 ,Mar 17,04:43 ,SUCCESS
d_isso_actvy_log_uld_cln.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
#############################################################################################################################
輸出文件:
==================== ============================== ======================== ==============================
JOB STATUS - Activity
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
==================== ============================== ======================== ==============================
JOB STATUS - Schedule
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
==================== ============================== ======================== ==============================
JOB STATUS - Linkage
==================== ============================== ======================== ==============================
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
在上述2個文件(文件1 & file2)3行對於所有的3 分區是不同的,所以我想將3 row frm file2只寫入到一個新文件 (輸出文件)。所以我需要一個腳本,在兩個 文件之間找到不匹配的行,並在同一分區下寫入第三個文件。
我試着用下面的查詢,但IAM無法得到輸出結果 下對應的分區
awk 'NR==FNR && !/^=/{a[$0]++;next} !/^=/{if(/^JOB /){y=$0;tmp getline;print tmp;print y}if(!a[$0]){print $0}}' file1 file2
我得到的輸出象下面這樣,但我需要一個像輸出文件輸出:
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
JOB NAME ,ODATE ,START ,FINISH ,STATUS
d_voy_svc_sesn_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
d_svc_evt_sumry_ld_ctm.ksh ,20110317 ,Mar 17,03:20:49 ,Mar 17,03:31 ,SUCCESS
嘿,夥計,你可以詳細解釋一個示例代碼 – user672556 2011-03-25 06:34:45