gpt4 book ai didi

linux - 如何迭代 4 个变量并在 5 行中比较其中 2 个变量?

转载 作者:太空宇宙 更新时间:2023-11-04 05:04:37 24 4
gpt4 key购买 nike

这个问题已经解决了,但是如果我的文件(text 和 text2)像下面的格式,它将如何工作

LOGICAL UNIT NUMBER 150
UID: 60:06:01:60:10:20:2E:150
LOGICAL UNIT NUMBER 201
UID: 60:06:01:60:BB:20:2E:201
LOGICAL UNIT NUMBER 30
UID: 60:06:01:60:BB:10:2E:30
LOGICAL UNIT NUMBER 50
UID: 60:06:01:60:BB:10:2E:50
LOGICAL UNIT NUMBER 1500
UID: 60:06:01:60:BB:10:2E:1500
LOGICAL UNIT NUMBER 100
UID: 60:06:01:60:BB:10:2E:100
LOGICAL UNIT NUMBER 1100
UID: 60:06:01:60:BB:10:2E:100
LOGICAL UNIT NUMBER 1600
UID: 60:06:01:60:BB:10:2E:100

我有以下脚本,它工作正常,但对于某些问题,它仅在(i 和 y)中的相同值之间相等,而不是在所有值之间相等,因此我需要一些东西来比较所有值(i 变量与所有 y 变量),然后打印输出到文件中。

exec 5< <(awk '{IGNORECASE=1}/UID/ {print $4}' TEXT)
exec 6< <(awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT)
exec 7< <(awk '{IGNORECASE=1}/UID/ {print $4}' TEXT2)
exec 8< <(awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT2)
while read i <&5 && read x <&6 && read y <&7 && read z <&8
do
if [ "$i" == "$y" ]
then
echo " naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy - create -incremental -name copy_LUN_$i -srcwwn $x -destwwn $z -verify -linkbw 1024" >> INSHALLAH_KELSET
else
echo " no devices found "
fi
done

====================

我已经制作了 bash -x INSHALLAH 并在输出下方

$ bash -x INSHALLAH
+ exec
++ awk '{IGNORECASE=1}/UID/ {print $4}' TEXT
+ exec
++ awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT
+ exec
+ exec
++ awk '{IGNORECASE=1}/UID/ {print $4}' TEXT2
++ awk '{IGNORECASE=1}/LOGICAL/ {print $6}' TEXT2
+ read i
+ read x
+ read y
+ read z
+ '[' 50 == 50 ']'
+ echo ' naviseccli -h 10.1.xx.xx -user admin -password xxxxxx -scope 0 sancopy -create -incremental -name copy_LUN_50 -srcwwn 60:06:01:60:10:20:2E:00:24:DF:C9:2C:F4:AC:E2:11 -destwwn 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13 -verify -linkbw 1024'
+ read i
+ read x
+ read y
+ read z
+ '[' 201 == 201 ']'
+ echo ' naviseccli -h 10.1.xx.xx -user admin -password xxxxx -scope 0 sancopy -create -incremental -name copy_LUN_201 -srcwwn 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11 -destwwn 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11 -verify -linkbw 1024'
+ read i
+ read x
+ read y
+ read z
+ '[' 300 == 30 ']'
+ echo ' no devices found '
no devices found
+ read i
+ read x
+ read y
+ read z
+ '[' 150 == 1500 ']'
+ echo ' no devices found '
no devices found
+ read i
+ read x
+ read y
+ read z
+ '[' 1500 == 100 ']'
+ echo ' no devices found '
no devices found
+ read i

这是我的 2 个与下面相同的文件

文本

LOGICAL UNIT NUMBER 50 
UID: 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13
LOGICAL UNIT NUMBER 201
UID: 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11
LOGICAL UNIT NUMBER 30
UID: 60:06:01:60:10:20:2E:00:BA:FF:3B:5A:2C:9A:E2:11
LOGICAL UNIT NUMBER 1500
UID: 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:11
LOGICAL UNIT NUMBER 100
UID: 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:14
LOGICAL UNIT NUMBER 150
UID: 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13

文本2

LOGICAL UNIT NUMBER 50   
UID: 60:06:01:60:10:20:2E:00:24:DF:C9:2C:F4:AC:E2:11
LOGICAL UNIT NUMBER 201
UID: 60:06:01:60:10:20:2E:00:08:A5:91:23:FF:AF:E2:11
LOGICAL UNIT NUMBER 300
UID: 60:06:01:60:10:20:2E:00:BA:FF:3B:5A:2C:9A:E2:11
LOGICAL UNIT NUMBER 150
UID: 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:11
LOGICAL UNIT NUMBER 1500
UID: 60:06:01:60:BB:10:2E:00:96:6D:0E:82:B4:09:E3:13

我必须为 1000 台设备创建大约 1000 个 session ,并且无法创建手动。

最佳答案

根据您的问题,我不明白其他文件与 i 和 y 值有何关系。下面是将 file1 和 file2 的所有值进行比较的简化版本。

while read i<&5; 
do
while read y<&7;
do echo $i,$y;
done 7< <(awk '{print}' t2.txt) ;
done 5< <(awk '{print}' t1.txt)

这可能对您有帮助:

while read i && read j;
do
while read y && read z;
do
if [ "$i" == "$y" ]
then
echo " naviseccli -h 10.1.xx.xx -user admin -password xxxx -scope 0 sancopy - create -incr
emental -name copy_LUN_$i -srcwwn $j -destwwn $z -verify -linkbw 1024" >> INSHALLAH_KELSET
else
echo " no devices found "
fi
done < <(awk '{IGNORECASE=1; OFS="\n"}/UID/ {print $4, $6}' TEXT2) ;
done < <(awk '{IGNORECASE=1; OFS="\n"}/UID/ {print $4, $6}' TEXT)

关于linux - 如何迭代 4 个变量并在 5 行中比较其中 2 个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20247344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com