比较这两个文件并移动第三个文件中的不同记录

时间:2011-03-23 07:11:39

标签: unix

嗨,我还有一个绕口令你们所有人;我有2个文本文件,我需要在行中找到diff并在第三个文件中写入,但是在相同的分区下。

例如:

档案: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个文件(file1& file2)中,3&对于所有3个,4行是不同的 分区,所以我想写3& 4行frm file2仅限于一个新文件 (输出文件)。所以我需要一个脚本,找到两个之间不匹配的行 文件并在同一分区下的第三个文件中写入。

我尝试使用以下查询,但我无法获得输出结果 相应的分区

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 

3 个答案:

答案 0 :(得分:0)

使用命令行中的diff工具。使用sed或grep等工具过滤输出,然后将其重定向到目标文件。

答案 1 :(得分:0)

也许是{p> comm -1 file1 file2 | sed 's/^\t//'? (您可能需要使用文字标签而不是\tCtrl-VTab。)

答案 2 :(得分:0)

使用差异工具。请参阅man页面寻求帮助。