Search of multiple numeric entries in an output file

Hello Tech Guys,

I have two files named check.txt and output.txt

Content of check.txt

620070527336551	 40201800027285
620070551928314	 40201800027285
620070534376312	 40201800027285
620070536668046	 02711306140261
620070248491123	 02711306140261
620070553851296	 02711306140261
620070446225438	 02711306140261
620070544871702	 02711306140261

Content of output.txt

# extended LDIF
#
# LDAPv3
# base <data=40201800027285
# filter: (objectclass=*)
# requesting: ALL
#

# 40201800027285
dn: data=40201800027285
data: 40201800027285
objectClass: device2g3g
locked: 000000000000000
locked: 620070527336551
locked: 620070000095731
locked: 620070534376312

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1
# extended LDIF
#
# LDAPv3
# base <data=02711306140261
# filter: (objectclass=*)
# requesting: ALL
#

# 02711306140261
dn: data=02711306140261
data: 02711306140261
objectClass: device2g3g
locked: 620070263383027
locked: 620070551073690
locked: 620070446225438
locked: 620070555544259
locked: 620070453835231
locked: 620070248491123
locked: 620070556469603
locked: 620070536668046

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

The output.txt contains the search of two numeric data numbers i.e. 40201800027285 and 02711306140261 (could be more than two). Against each of these two numeric values the system provided the total number of locked items (could be more). Now I need to compare these locked items alongwith the items present in search.txt in 1st coloum and need to know the difference. The desired output after comparing these two files will be saved in difference.txt and should be like below:

data: 40201800027285
locked: 620070527336551    620070534376312
unlocked: 620070551928314

data: 02711306140261
locked: 620070536668046    620070248491123    620070446225438
unlocked: 620070553851296    620070544871702

Kindly suggest a code for the above described requirement. Efforts will be really appreciable.

Thanks.

Any attempts on your side?

Hello. Well no because I am new to shell scripting and doesn't know how to compare and make such logic. Any input would be highly appreciable.

I know I shouldn't be doing this and should make you work it out yourself, but I'll bend the rules a bit IF you go though the code yourself try to understand it yourself with the minimum of guidance...
awk -f xtreme.awk check.txt output.txt where xtreme.awk is:

FNR==NR {f1[$1]=$2;next}
/^data:/ { data=$2;next}
data && /^locked:/ && $2 in f1 { locked[$2];next}
data && !NF {
   printf("data: %s\n%s", data, "locked:")
   for(i in locked)
     printf("%s%s", OFS, i)

   printf("%s%s",  ORS, "unlocked:")
   for(i in f1)
     if (!(i in locked) && f1==data)
        printf("%s%s", OFS, i)
   print ORS
   data="";split("", locked)
}

produces:

data: 40201800027285
locked: 620070534376312 620070527336551
unlocked: 620070551928314

data: 02711306140261
locked: 620070446225438 620070248491123 620070536668046
unlocked: 620070553851296 620070544871702
1 Like

This is super !!! I have tried once and it really works. Thank you so much for putting an effort. I will try to understand the logic as much as I can. Loving this forum. Thanks again.