CSV를 처리하는 bash 스크립트에서 awk를 사용하고 있습니다. AWK이 수행 : 내가 아는 awk로 csv에 헤더가있는 새 열을 추가하는 방법
# 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
같은 새로운 CSV가 보이도록
# 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
나는, 새로운 열 헤더를 갖고 싶어 :이 변환을 수행
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
별도로 첫 번째 행에서 수행 할 작업을 지정하는 방법이 있지만이를 이해할 수는 없습니다.
가, 감사합니다. 두 번째 해법에서''' "% s % s"'''을 설명 할 수 있습니까? –
@dataprincess, 환영합니다. 다행히 도움이되었습니다. 나는 코드에 대해서도 설명을 추가했다. 친절하게도 당신이 어떤 질문이 있으면 알려줘. – RavinderSingh13