मेरा शुद्ध बैश रास्ता
केवल के रूप में इस चर शामिल vol-XXX
जहां XXX
एक हेक्साडेसिमल संख्या है, वहाँ का उपयोग कर एक त्वरित तरीका है बैश सरणियों
unset A B a b c i # Only usefull for re-testing...
A=(vol-175a3b54 vol-382c477b vol-8c027acf vol-93d6fed0 vol-71600106 vol-79f7970e
vol-e3d6a894 vol-d9d6a8ae vol-8dbbc2fa vol-98c2bbef vol-ae7ed9e3 vol-5540e618
vol-9e3bbed3 vol-993bbed4 vol-a83bbee5 vol-ff52deb2)
B=(vol-175a3b54 vol-e38d0c94 vol-2a19386a vol-b846c5cf vol-98c2bbef vol-7320102b
vol-8f6226cc vol-27991850 vol-71600106 vol-615e1222)
for i in ${A[@]#vol-};do
[ "${a[$((16#$i))]}" ] && echo Duplicate vol-$i in A
((a[$((16#$i))]++))
((c[$((16#$i))]++))
done
for i in ${B[@]#vol-};do
[ "${b[$((16#$i))]}" ] && echo Duplicate vol-$i in B
((b[$((16#$i))]++))
[ "${c[$((16#$i))]}" ] && echo Present in A and B: vol-$i
((c[$((16#$i))]++))
done
यह आउटपुट होना चाहिए:
Present in A and B vol-175a3b54
Present in A and B vol-98c2bbef
Present in A and B vol-71600106
इस स्थिति में, आप पर्यावरण को कोसते हैं:
set | grep ^c=
c=([391789396]="2" [664344656]="1" [706295914]="1" [942425979]="1" [1430316568]="1"
[1633554978]="1" [1902117126]="2" [1931481131]="1" [2046269198]="1" [2348972751]="1"
[2377892602]="1" [2405574348]="1" [2480340688]="1" [2562898927]="2" [2570829524]="1"
[2654715603]="1" [2822487781]="1" [2927548899]="1" [3091645903]="1" [3654723758]="1"
[3817671828]="1" [3822495892]="1" [4283621042]="1")
तो आप कर सकते हैं:
for i in ${!b[@]};do
[ ${c[$i]} -eq 1 ] &&
printf "Present only in B: vol-%8x\n" $i
done
यह प्रस्तुत करेगा:
Present only in B: vol-27991850
Present only in B: vol-2a19386a
Present only in B: vol-615e1222
Present only in B: vol-7320102b
Present only in B: vol-8f6226cc
Present only in B: vol-b846c5cf
Present only in B: vol-e38d0c94
लेकिन यह संख्यात्मक छँटनी है! यदि आप मूल आदेश चाहते हैं, तो आप:
for i in ${B[@]#vol-};do
[ ${c[((16#$i))]} -eq 1 ] && printf "Present in B only: vol-%s\n" $i
done
तो आप उसी क्रम में खंडों को जमा करें जैसा कि प्रस्तुत किया गया है:
Present in B only: vol-e38d0c94
Present in B only: vol-2a19386a
Present in B only: vol-b846c5cf
Present in B only: vol-7320102b
Present in B only: vol-8f6226cc
Present in B only: vol-27991850
Present in B only: vol-615e1222
या
for i in ${!a[@]};do
[ ${c[$i]} -eq 1 ] && printf "Present only in A: vol-%8x\n" $i
done
केवल ए में दिखाने के लिए :
Present only in A: vol-382c477b
Present only in A: vol-5540e618
Present only in A: vol-79f7970e
Present only in A: vol-8c027acf
Present only in A: vol-8dbbc2fa
Present only in A: vol-93d6fed0
Present only in A: vol-993bbed4
Present only in A: vol-9e3bbed3
Present only in A: vol-a83bbee5
Present only in A: vol-ae7ed9e3
Present only in A: vol-d9d6a8ae
Present only in A: vol-e3d6a894
Present only in A: vol-ff52deb2
या और भी:
for i in ${!b[@]};do
[ ${c[$i]} -eq 2 ] && printf "Present in both A and B: vol-%8x\n" $i
done
होगा फिर से प्रिंट :
Present in both A and B: vol-175a3b54
Present in both A and B: vol-71600106
Present in both A and B: vol-98c2bbef