0

I have comma separated file:

ID,Disease,Status
Sample1,Disease1,High
Sample1,Disease2,Low
Sample1,Disease3,Medium
Sample2,Disease1,Low
Sample2,Disease2,Medium
Sample2,Disease3,Low

The first field is the ID number, the second field is the name of the disease and the third column is the risk status of the individual for that disease. I need to have all diseases in rows and IDs in column. Each ID should have be allotted one row with all disease risk status mentioned column wise. So, the output should be:

Expected Output file:

ID,Disease1,Disease2,Disease3
Sample1,High,Low,Medium
Sample2,Low,Medium,Low
1
  • It depends on quite some factors. Is Your data sorted? Is it much data so is there need for streaming processing? Are there all rows for each Disease for every ID? In Your example it not much data but this would not matter much since it's sorted anyway. Also there are rows for each Disease for every ID. That would be the easiest case and wouldn't not have any issues on huge number of rows. – EOhm Nov 13 '19 at 7:18
0
apt install rs
echo -e "1,2\n3,4" | rs -c',' -C',' -T
1,3,
2,4,

There are many ways to transpose data for every language and even a few dedicated tools;

https://stackoverflow.com/questions/1729824/an-efficient-way-to-transpose-a-file-in-bash

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.