-2

i have a file txt which has data as below:

k1|k2|k3
1|65|98
2|42|55
3|21|56
4|76|89
5|34|93
6|78|22

and i want to transform the data like this:

k1|1|2|3|4|5|6
k2|65|42|21|76|34|78
k3|98|55|56|89|93|22

Any help can give me good lesson. Btw im new in coding and i want to learn shell script. Thank You

Onta Ss
  • 1
  • 2
  • 1
    On SO we do encourage users to add their efforts in their posts, so kindly do edit your question with same and let us know then. – RavinderSingh13 Jun 15 '20 at 06:22

1 Answers1

1

Using GNU datamash makes it trivial:

$ datamash -t'|' transpose < input.txt
k1|1|2|3|4|5|6
k2|65|42|21|76|34|78
k3|98|55|56|89|93|22
Shawn
  • 47,241
  • 3
  • 26
  • 60