> lsblk -o NAME,LABEL,FSTYPE,MOUNTPOINT,SIZE,TYPE -x NAME
NAME LABEL FSTYPE MOUNTPOINT SIZE TYPE
nvme0n1 894.3G disk
nvme0n1p1 [SWAP] 4G part
nvme0n1p2 1G part
nvme0n1p3 root /home/cg/root 889.3G part
I need the output of this command in csv format, but all the methods I've tried so far don't handle the empty values correctly, thus generating bad rows like these I got with sed:
> lsblk -o NAME,LABEL,FSTYPE,MOUNTPOINT,SIZE,TYPE -x NAME | sed -E 's/ +/,/g'
NAME,LABEL,FSTYPE,MOUNTPOINT,SIZE,TYPE
nvme0n1,894.3G,disk
nvme0n1p1,[SWAP],4G,part
nvme0n1p2,1G,part
nvme0n1p3,root,/home/cg/root,889.3G,part
Any idea how to add the extra commas for the empty fields?
NAME,LABEL,FSTYPE,MOUNTPOINT,SIZE,TYPE
nvme0n1,,,,894.3G,disk
nvme0n1,,,,894.3G,diskcould you please explain how there are 4 commas there? Because there are more spaces so shouldn't commas be more than 4? Kindly confirm once.lsblk --jsonand work with e.g.jplsbkkhas no option to outputtabsas separator in this output format it's gonna get very tricky to reformat reliably.