雨过天晴12
2019-01-02 19:43
采纳率: 66.7%
浏览 1.4k

请教如何把字符串作为分隔符把文件分割成不同文件

如何以0 rows affected 作为分割符把前后的文件内容分割成不同文件呢?

CTY,COMM_YR,COMM_MTH,SEQ_NO,LAST_UPT_CTY,LAST_UPT_ID,LAST_UPT_TIME
559,2018,10,1, ,FMSCCCM ,2018-10-19 15:04:55.511
602,2018,10,1,602,44638994,2018-10-22 02:49:28.944
608,2018,10,1,608,44638994,2018-10-22 02:49:28.946
JP1,2018,10,1,JP1,44638994,2018-10-22 02:49:29.102
897,2018,12,1, ,FMSCCCM ,2018-10-19 15:19:15.305
111,2018,10,1,602,FMSCCCM ,2018-10-19 15:04:55.0
0 rows affected
TRFM_FILE_MSTR_TGT_ID,PROC_STEP_ID,TARGET_FILE_FORMAT_ID,TRFM_FILE_MSTR_ID,TARGET_FILE_CD,TARGET_FILE_NAME,TARGET_TRIGGER_JOB,APPR_STATUS,LAST_ACT_USER_ID,CREATE_TIMESTAMP,LAST_UPT_TIME,LAST_ACT_SYS_CD
7,4,4,4,CD1 ,CODE-1,FMSBMTR1,Approved,201682,2018-12-18 10:54:09.46366,2018-12-18 10:54:09.46366,null
5,3,3,3,CD1 ,CODE-1,FMSBMTR1,Approved,201682,2018-12-18 10:54:09.565309,2018-12-18 10:54:09.565309,null
3,2,2,2,CD1,CODE-1,FMSBMTR1,Approved,201682,2018-12-18 10:54:09.566149,2018-12-18 10:54:09.566149,null
1,1,1,1,CD1,CODE-1,FMSBMTR1,Approved,201682,2018-12-18 10:54:09.567031,2018-12-18 10:54:09.567031,null
0 rows affected
PROC_FUNC_RULE_ID,FUNC_RULE_SEQ,PROCESS_TYPE_ID,PROC_FUNC_ID,APPR_STATUS,LAST_ACT_USER_ID,CREATE_TIMESTAMP,LAST_UPT_TIME,LAST_ACT_SYS_CD
1,1,1,1,Approved ,201682,2018-12-18 10:52:55.331338,2018-12-18 10:52:55.331338,null
2,2,2,2,Approved ,201682,2018-12-18 10:52:55.452795,2018-12-18 10:52:55.452795,null
3,3,3,3,Approved ,201682,2018-12-18 10:52:55.453532,2018-12-18 10:52:55.453532,null
4,4,4,4,Approved ,201682,2018-12-18 10:52:55.454214,2018-12-18 10:52:55.454214,null
0 rows affected

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • yzypals 2019-01-07 15:52
    已采纳
    
    #!/bin/bash
    i=0
    while read line  
    do
            if [[ $line =~ '0 rows affected'  ]];then
                    ((i++))
            else
                    echo $line >> $i.txt
            fi
    done < abc.txt
    

    上面代码试用情况 是要求0 rows affected 单独成行的

    打赏 评论

相关推荐 更多相似问题