txt结构如下
cost_amount,cost_type,coupon_amount,coupon_name,coupon_source,coupon_type, ctime, etime, id,order_amount_limit, order_id, phone, stime,user_coupon_status, user_id, utime, uuid,wm_act_coupon_channel_config_id,wm_act_coupon_channel_template_id,wm_act_coupon_config_id,wm_act_coupon_use_config_id,first_order_limit, use_conditions,forbidden_use_conditions, charge_config,activity_mutex_attr,outer_code,pay_status,wm_act_coupon_template_id,set_id_insert,set_id_update,max_deduct_amount,total_count,surplus_count,used_count,freezed_count, dt
[0,0,5820,畅爽可口可乐三人餐,2,2,1557999047,1559231999,60306207190,0,1050674240815626,,1557999047,1,797957664,1558666811,,4927,13,101531884,-1,0,{"activity_id":"616088"},null,{"an":"PN18FDDD9S000044T534R842X00088","charge_method":1,"charge_side":"1","charge_type":0},null,null,0,45,10,10,0,1,0,1,0,20190516]
awk -F ',' 'NR>=2 {print $15,$9}' 20190517.txt | sort | awk '{a[$1]=a[$1]''''$2","}END{for(i in a){print i,a[i]}}' > 2019-05-17.txt
1、提取第二行开始的 第9列与15列 并排序;
2、将第一列作为数组a的下标,通过 '''' 四个单引号进行字符串的拼接,大概格式如下
a[第一列] = a[第一列] + a[第二列] + ','
3、最后循环输出数组a ,即完成了 相同列的其他数据列的数据合并
源文件:
a xxxx
b yyyy
a zzzzz
合并后:
a xxxx,zzzz,
b yyyy