如果仅最新日期(2到8列)备份模式“失败”则打印

时间:2014-08-24 13:48:49

标签: linux bash awk sed

以下是要求。

  1. 忽略包含模式“SET SNAP_ID”或“Shadow Copy Components:\”的行。
  2. 忽略第2列至第8行的行为空。
  3. 打印包含“失败”模式的行。
  4. 如果只有最新日期(2到8)备份的模式“失败”,则打印。 (如果在前一个日期“失败”并在结束日期“成功”,则忽略。)
  5. 请附上html报告和csv文件。
  6. 使用bash脚本如何在csv文件上从linux服务器实现上述条件。

    我尝试了以下内容:

    cat csv_report.csv | awk '!/SET SNAP_ID/' | awk '!/Shadow/'
    
    cat csv_report.csv | awk -F'=' '!/^$/{arr[$1]=$2}END{for (x in arr) {print x"="arr[x]}}'
    
    cat csv_report.csv | grep "Failed"
    

    csv_report.csv如下 -

    Client Name Friday 08/8 Saturday 08/9 Sunday 08/10 Monday 08/11 Tuesday 08/12 Wednesday 08/13 Thursday 08/14 Friday 08/15 elgar.ppp->E:\ Failed Full FS_Win_801_Thu_B Full_Backup 0B;
    gershwin.ppp->D:\ Failed Full FS_Win_801_Thu_B Full_Backup 0B;
    mozart.ppp->D:\ Successful Full FS_Win_801_Fri_B Synthetic_Full 0B; Failed Full FS_Win_801_Fri_B Full_Backup 0B;
    nicklaus.ppp->C:\ Successful Full FS_Win_801_Fri_B Synthetic_Full 0B; nicklaus.ppp->D:\ Successful Full FS_Win_801_Fri_B Synthetic_Full 0B; Failed Full FS_Win_801_Fri_B Full_Backup 0B; Failed Full FS_Win_801_Fri_B Synthetic_Full 0B; samgdef00.ppp->C:\ Successful Full FS_Win_801_Thu_B Full_Backup 0B; Failed Full FS_Win_801_Thu_B Full_Backup 0B;
    samgdef00.ppp->E:\ Failed Full FS_Win_801_Thu_B Full_Backup 0B;
    samgdef06.ppp->C:\ Successful Full FS_Win_801_Fri_B Synthetic_Full 0B; Failed Full FS_Win_801_Fri_B Synthetic_Full 0B; 
    

1 个答案:

答案 0 :(得分:0)

awk -v FS=';' '{if(NF>2&&$0~/Failed/&&$0~!/SET SNAP_ID/&&$0~!/Shadow/)print $0}' file