user3024232 user3024232 - 3 months ago 8
Linux Question

How to iterate for 4 variables and compare between 2 of them for may lines?

This has already been solved but what if my file (text and text2) were like the below format how it will work

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 have the following script and it is working fine but for some matter it is only make equal between only identical values in (i and y) not between all values so I need something to compare all (i variables with all y variables) and then print the out put on the file.

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


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

I already made
bash -x INSHALLAH
and below the output

$ 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


This is my 2 files identical to below

TEXT

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


TEXT2

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


I have to create about 1000 sessions for 1000 devices and no way to create manual.

Answer

From your question, I don't understand how the other files are related to i and y values. Here's the simplified version for comparing all values of file1 against 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)

This might help you:

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)
Comments