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

如何以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个回答


#!/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 单独成行的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!