I'm using some awk inside a bash script that's handling CSVs. The awk does this:
ORIG_FILE="score_model.csv"
NEW_FILE="updates/score_model.csv"
awk -v d="2017_01" -F"," 'BEGIN {OFS = ","} {$(NF+1)=d; print}' $ORIG_FILE > $NEW_FILE
Which does this transformation:
# before
model_description, type, effective_date, end_date
Inc <= 40K, Retired, 08/05/2016, 07/31/2017
Inc > 40K Age <= 55 V5, Retired, 04/30/2016, 07/31/2017
Inc > 40K Age > 55 V5 , Retired, 04/30/2016, 07/31/2017
# after, bad
model_description, type, effective_date, end_date, 2017_01
Inc <= 40K, Retired, 08/05/2016, 07/31/2017, 2017_01
Inc > 40K Age <= 55 V5, Retired, 04/30/2016, 07/31/2017, 2017_01
Inc > 40K Age > 55 V5 , Retired, 04/30/2016, 07/31/2017, 2017_01
I want the new column to have a header, so that the new CSV looks like
# after, desired
model_description, type, effective_date, end_date, cmpgn_group
Inc <= 40K, Retired, 08/05/2016, 07/31/2017, 2017_01
Inc > 40K Age <= 55 V5, Retired, 04/30/2016, 07/31/2017, 2017_01
Inc > 40K Age > 55 V5 , Retired, 04/30/2016, 07/31/2017, 2017_01
I know there's a way to specify what to do in the first row separately, but I haven't been able to figure it out.