简体   繁体   中英

BASH Getting output on the same line

I have a raid setup and I would like to match the Device ID with the Mounted Drive. Thankfully the outputs are the same 0-15. The following commands I am using is:

MegaCli -LdpdInfo -a0 | awk '/Target Id:/ {print $3}'

MegaCli -LdpdInfo -a0 | awk '/Device Id:/ {print $3}'

lsscsi | awk '/MR9260-16i/ {print $6}'

I was working on a simple script that started with one put and worked, then I added the second output which didn't work but added the results after the first output like so:

/dev/sdb
/dev/sdc
/dev/sdd
/dev/sde
/dev/sdg
/dev/sdh
/dev/sdi
/dev/sdj
/dev/sdk
/dev/sdl
/dev/sdm
/dev/sdn
/dev/sdo
/dev/sdp
/dev/sdq
/dev/sdr: 104
113
210
211
212
216
217
218
219
220
221
222
223
224
225
226

And I was like "Crap... that didn't work" anyways here is my script

# Prints the Device ID of each drive on the Raid Controller.
perform_target() {
    MegaCli -LdpdInfo -a0 | awk '/Device Id:/ {print $3}'
}

# Prints each mounted drive out that is on the Raid Card.
perform_drive() {
    lsscsi | awk '/MR9260-16i/ {print $6}'
}
    printf ' %s\n' "$(perform_drive)" "$(perform_target)";

If you have two columns in separate files, you can use paste to join them:

$ cat file1
/dev/sdb
/dev/sdc
/dev/sdd

$ cat file2
104
113
210

$ paste file1 file2
/dev/sdb        104
/dev/sdc        113
/dev/sdd        210

you don't need to invoke MegaCli twice:

MegaCli -LdpdInfo -a0 | awk <<'EOF'
  /Target Id:/ {printf("%s: ", $3)}
  /Device Id:/ {print $3}
EOF

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM