Duplicate a CSV column in Bash

Viewed 4936

I have an issue where a client needs to duplicate a column in a CSV file. The values are always going to be identical and unfortunately our API doesn't allow for duplicate columns to be specified in the JSON.

For example I have the following column structure and values:

Name, Surname, City, Age, Job
John, Doe, Johannesburg, 28, Technical Support

Now I need to duplicate City so the output should be:

Name, Surname, City, City Again, Age, Job
John, Doe, Johannesburg, Johannesburg, 28, Technical Support

The column needs to be placed after that which will be duplicated. The value is also dependent on this first column.

4 Answers
Related