我有2个命令在我的linux系统上输出设备:
$ devlist -t csv -o device,vol_name
device,vol name,
/dev/mapper/mpath62,volume1,
/dev/mapper/mpath63,my_volume,
/dev/mapper/mpath64,foo,
/dev/mapper/mpath65,bar,
/dev/mapper/mpath66,2nd_vol,
$ multipathd -k'show maps'
name sysfs uuid
mpath62 dm-0 20017380029ab0043
mpath65 dm-1 20017380029ab0044
mpath66 dm-2 20017380029ab0045
mpath63 dm-3 20017380029ab0046
mpath64 dm-4 20017380029ab0047
如何合并输出以进行打印(最好不要创建临时文件):
device,vol name,
/dev/dm-0,volume1,
/dev/dm-3,my_volume,
/dev/dm-4,foo,
/dev/dm-1,bar,
/dev/dm-2,2nd_vol,
由于
答案 0 :(得分:1)
您可以将awk
与process substitution
:
awk -F '[/, ]+' 'FNR==NR{a[$1]=$2; next}
FNR==1{print;next}
$4 in a{printf "/%s/%s,%s,\n", $2, a[$4], $(NF-1)}
' <(multipathd -k'show maps') <(devlist -t csv -o device)
device,vol name,
/dev/dm-0,volume1,
/dev/dm-3,my_volume,
/dev/dm-4,foo,
/dev/dm-1,bar,
/dev/dm-2,2nd_vol,