Hi All,
The below code is splitting the file "data.csv" into several files based on the"client_code" column.
date_yyyymmdd=$(my_date "" -e"%Y%m%d")
file_format="_$date_yyyymmdd.csv
awk '{print $2, $3> DIR"/clients_" $1 file_out}' FS=' *; *' OFS=";" DIR="$TEMPL" file_out="_$file_format" $TEMPL/data.csv
data.csv
client_code;contact_name;product_id
XYZ;AMAR ;AB123456
ABC;KIRAN;CB789
XYZ;RAJ;CS78890
ABC;KAMESH;A33535335
XYZ;SOM ;MD6546474777
XYZ;GANE ;MS657869933553666747
The splitted files are as follows.
clients_ABC_20150615.csv
ABC;KIRAN;CB789
ABC;KAMESH;A33535335
clients_XYZ_20150615.csv
XYZ;AMAR ;AB123456
XYZ;RAJ;CS78890
XYZ;SOM ;MD6546474777
XYZ;GANE ;MS657869933553666747
clients_client_code_20150615.csv
client_code;contact_name;product_id
The splitted files are not having this heading client_code;contact_name;product_id
I want client_code;contact_name;product_id this heading
in these clients_ABC_20150615.csv and clients_XYZ_20150615.csv splitted files.
Please help me.
Thanks