Skip to main content

Create a duplicate record based on a condition

I need to write a shell script where I have to create a duplicate record based on a condition and then change the value in a column of the new row which will be created.

I am trying to create a duplicate record based on a condition and then replace on column in the duplicate row.

Example:

Input will be

Col1,Col2,Col3,Col4,COl5

1234,abcd,abcd,wxyz,USD
2345,abcd,abcd,wxyz,USD
3456,abcd,abcd,wxyz,EUR

If the last column ie; col5 is EUR, then one more row should be created with change in column value.

Output should be

Col1,Col2,Col3,Col4,Col5

1234,abcd,abcd,wxyz,USD
2345,abcd,abcd,wxyz,USD
3456,abcd,abcd,wxyz,EUR
3456,abcd,abcd,wxyz,AUD

Please help me with this.

Rakesh K
  • 151
  • 1
  • 2
  • 10