CSV Transpose
by nooobeee from LinuxQuestions.org on (#5ANHZ)
I have a CSV that I'm looking to transpose for logstash ingestion but I think i've reached the extent of my limited expertise. I have a CSV similar to the following:
Code:DeviceID,12345678,12245678,12335678,12344678
05/10/2020 00:30,0.96,1.6,4.48,0.48
05/10/2020 01:00,0.64,1.6,2.56,3.52
05/10/2020 01:30,1.28,1.44,3.04,3.04My intended output is:
Code:05/10/2020 00:30,12345678,0.96
05/10/2020 00:30,87654321,1.6
05/10/2020 00:30,56784321,4.48
05/10/2020 00:30,65473195,0.48
05/10/2020 01:00,12345678,0.64
05/10/2020 01:00,87654321,1.6
05/10/2020 01:00,56784321,2.56
05/10/2020 01:00,65473195,3.52
05/10/2020 01:30,12345678,1.28
05/10/2020 01:30,87654321,1.44
05/10/2020 01:30,56784321,3.04
05/10/2020 01:30,65473195,3.04While I'm more familiar with tools like awk, it seems like I may need something like perl for this. I have something that sorta does some of the task but is definitely not quite right.
Code:perl -F, -lane '$s=shift @F;print "$s,$_" for @F'I was wondering if there was someone out there that's more proficient with awk, sed, or even perl that could help.


Code:DeviceID,12345678,12245678,12335678,12344678
05/10/2020 00:30,0.96,1.6,4.48,0.48
05/10/2020 01:00,0.64,1.6,2.56,3.52
05/10/2020 01:30,1.28,1.44,3.04,3.04My intended output is:
Code:05/10/2020 00:30,12345678,0.96
05/10/2020 00:30,87654321,1.6
05/10/2020 00:30,56784321,4.48
05/10/2020 00:30,65473195,0.48
05/10/2020 01:00,12345678,0.64
05/10/2020 01:00,87654321,1.6
05/10/2020 01:00,56784321,2.56
05/10/2020 01:00,65473195,3.52
05/10/2020 01:30,12345678,1.28
05/10/2020 01:30,87654321,1.44
05/10/2020 01:30,56784321,3.04
05/10/2020 01:30,65473195,3.04While I'm more familiar with tools like awk, it seems like I may need something like perl for this. I have something that sorta does some of the task but is definitely not quite right.
Code:perl -F, -lane '$s=shift @F;print "$s,$_" for @F'I was wondering if there was someone out there that's more proficient with awk, sed, or even perl that could help.