1

I have several csv table as follow:

YEAR;MONTH;DAY;RES1;RES2
1971;1;1;1206.1;627
1971;1;2;1303.4;654.3
1971;1;3;1248.9;662
1971;1;4;1188.8;666.8

From this I would like to create a new column that concatenate the values of the columns MONTH and DAY. Therefore the output should look like that:

YEAR;MONTH;DAY;RES1;RES2;MONTHDAY
1971;1;1;1206.1;627;11
1971;1;2;1303.4;654.3;12
1971;1;3;1248.9;662;13
1971;1;4;1188.8;666.8;14
  • After reading your previous question, this one does make much more sense. You should close the other one which is pointless. – Julie Pelletier Aug 19 '16 at 17:19
5

Since you're happy for the header line to also be merged this is simple awk

awk -F';' -vOFS=';' '{ $(NF+1)=$2$3 ; print}'

Basically we add a new field $(NF+1) which consists of $2$3, which merges those fields. With OFS=';' the fields are output with ; separator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.