1

I would like to sort the output of multipath -ll into a csv type of file using bash script. For example # multipath -ll would give the following output

360060e80056fc30000006fc30000513c dm-41 HITACHI,OPEN-V
 \_ 4:0:0:45 sdcm 69:160 [active][ready]
 \_ 3:0:0:45 sdcn 69:176 [active][ready]
360060e80056fc30000006fc300005162 dm-31 HITACHI,OPEN-V
 \_ 3:0:0:36 sdbu 68:128 [active][ready]
 \_ 4:0:0:36 sdbv 68:144 [active][ready]
360060e80056fc30000006fc300005127 dm-56 HITACHI,OPEN-V
 \_ 3:0:0:6  sdg  8:96   [active][ready]
 \_ 4:0:0:6  sdt  65:48  [active][ready]

What I would like is to create a csv file that would be in this format

LUN ID no., SCSI DEVICE1, SCSI DeVICE2
360060e80056fc30000006fc300005127,sdg,sdt
360060e80056fc30000006fc300005162,sdbu,sdbv

I am just looking for a basic idea of how it could be done, not the entire script. Any help would be greatly appreciated.

1 Answer 1

2
> awk '/^[^ ]/ {printf "\n%s",$1; next}; { printf ",%s",$3; }' file

360060e80056fc30000006fc30000513c,sdcm,sdcn
360060e80056fc30000006fc300005162,sdbu,sdbv
360060e80056fc30000006fc300005127,sdg,sdt
2
  • thanks a lot, exactly what I need. Could you please explain what it does so that I can modify it in the future if I need to? Dec 17, 2014 at 15:06
  • @Linuxnoob339 This command treats lines beginning with a space and the other ones differently. From the lines without leading space the first element is printed (after a newline because the newline is not printed at the end). From the other lines the third element is printed (after a comma). Using printf instead of print avoids the trailing newline. Dec 17, 2014 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .