I have a file sales_$date.csv
. I want to split it into 10 files based on the last digit of first column (ITEM). so in reality file would be split in 10 files as sales_$date-01.csv
, sales_$date-02.csv
,.. and so on. Also I need to keep the header in all the files. Length for column (ITEM) value is not fixed. This process needs to run every :45 minutes every day. Below is the example
sales_$date.csv file: FILE=sales_$date ITEM,QTY,STORE,BUYABLEFLAG 4000,1,13805,Y 4001,3,1456,N 5010,2,14534,Y 7200,5,14566,N 4002,2,6534534,N 5611,9,34234,Y 7832,32,6575,N
sales_$date-01.csv should have the records for items (see the first column ITEM value) ending with 0:
ITEM,QTY,STORE,BUYABLEFLAG
4000,1,13805,Y
5010,2,14534,Y
7200,5,14566,N
sales_$date-02.csv should have the records for items (see the first column ITEM value) ending with 1:
ITEM,QTY,STORE,BUYABLEFLAG
4001,3,1456,N
5611,9,34234,Y
sales_$date-03.csv should have the records for items (see the first column ITEM value) ending with 2:
ITEM,QTY,STORE,BUYABLEFLAG
4002,2,6534534,N
7832,32,6575,N
Also all the file names i.e. sales_date-01,sales_date-02,sales_date-03 are in a variable called FILE_NAME.