Need assistance with an IF statement to compare a list of SHA keys between two repositories.

Hello.

My first time here.

What I am trying to do is this.

FileA is located on a web server
FileB is located on local storage

Both files contain a large list of information of not only SHA keys but versions, and other information.

I need a statement that can compare between FileA and FileB and ONLY the SHA keys in the file.

  • If the statement finds that ALL of the SHA key's listed on File A are ALSO in located anywhere in File B, its a match.
  • If it cannot find the SHA key on FileB, its is not a match and the missing SHA keys need to be printed.

You need a lot more than an if statement to do what you want to do. And, if you want our help we will need a lot more information:

  1. What operating system are you using?
  2. What shell are you using?
  3. What are the formats of files FileA and FileB ?
  4. Can you show us a representative sample of the contents of FileA and FileB and show us the results you hope to get when processing those two sample files?
  5. And, most importantly, please show us what you have tried to solve this problem on your own.

Assuming you already have the two file locally (you will need to fetch FileA from the web server using something like wget ).
Also that the SHA keys are a string of 64 hex digits (0-9 a-f) which are separated from other text in file by one or more white space characters.

You could collect the keys using grep like this:

$ grep -Eow '[0-9a-f]{64}' FileA > KeylistA
$ grep -Eow '[0-9a-f]{64}' FileB > KeylistB

Grep can then output any key(s) in KeylistA not in KeyListB like this.

$ grep -vf KeylistB KeylistA || echo "Files Match"
1 Like

Hello

OS:

NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
[removed links]
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

Shell:

$SHELL -version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later

Formats and Code:

Package: [package name]
Priority: extra
Section: --
Installed-Size: 12787
Maintainer: [Creator of the package]
Architecture: amd64
Source: [Source of the Package]
Version: [Version]
Depends: [Depends]
Filename: [Filename and directory of the file]
Size: [Filesize]
MD5sum: [checksum]
SHA1: [checksum]
SHA256: [checksum]
Description [description]
Homepage: [homepage]

Hi, thank you for this - I went ahead and tested this and it seems to work fine, I then modifed it to this format:

echo "The following keys were not found on the apt-mirror:" && grep -vf <(curl [repo-file] | grep �SHA256') <(cat [address-of-local-repo-file] | grep �SHA256') || echo "Files Match"

and this also seems to work.

So lets say I wanted to take a step further and wanted to also retrieve the program name and version of the repo's from 'ListA' that do not appear on ListB given that they are included in the list I mentioned above?

Thanks.

You could use awk like this:

awk '
  FNR==1 { file++ }
  /^Package: / { p = substr($0,10) }
  /^Version: / { v = substr($0,10) }
  /^SHA256: / {
      c = substr($0, 9)
      if(file==1) C[c]
      else if(!(c in C))
        printf "Package: %s (%s) SHA256 %s not found in repo\n", p, v, c
}' <(curl [repo-file]) [address-of-local-repo-file]
1 Like

That worked! Thank you!