consider a list of files in a particular directory(LIST A)

58623208 Sep 14 20:08 blbn_blfbe_drv
57904920 Sep 14 19:54 blbn_cycmn
55814208 Sep 14 06:02 clsa_Upd
38912000 Sep 14 19:12 cs_chgpp

and in another directory (LIST B)
58623208 Sep 14 20:08 blbn_blfbe_drv
57904920 Sep 14 19:54 blbn_cycmn
55814208 Sep 14 06:02 clsa_Upd
38912000 Sep 14 19:12 cs_chgpp
41107456 Sep 14 19:17 csmRFbe
39403520 Sep 14 19:09 csmUAddAct
39235584 Sep 14 19:20 csmUAddSub

where list A is a subset of list B

Now I want to search for files the files which are present in LIST A in LIST B
and compare each attribute(size,month,date,time,name) and print out the filename which
is not found in LIST B or if any attribute(size,month,date,time,name) is mismatching.

or
Display any message like all the files are found and all atributes are matching only if
all the files are found in LIST B and all its attributes are matching.

I donno what would be nice way to do this(may be i need awk to do this, ro some while loop)

Please suggest.

Dani AI

Generated

Quick summary and approach (for ): treat file name as the key, load LIST B into a lookup table, then iterate LIST A and compare the attributes. That keeps things simple and avoids brittle line-by-line position assumptions. was right to suggest scripting and sorting as a concept, but with an associative-array approach you do not need to sort first — the script below maps B by filename and checks A against it.

A compact, practical awk solution that assumes each line is "size month day time name" and the filename is the last token (no spaces in names):

awk '
NR==FNR {
    name = $NF
    b[name] = $1 " " $2 " " $3 " " $4
    seenB[name]=1
    next
}
{
    name = $NF
    a = $1 " " $2 " " $3 " " $4
    if (!(name in seenB)) {
        print "NOT FOUND in B: " name
        missing++
    } else {
        matched[name]=1
        if (a != b[name]) {
            print "ATTRIBUTE MISMATCH: " name
            print "  A: " a
            print "  B: " b[name]
            diff++
        } else ok++
    }
}
END {
    extra=0
    for (n in seenB) if (!(n in matched)) extra++
    if (missing==0 && diff==0) print "All files found and attributes match."
    else printf "Summary: missing=%d diffs=%d extra_in_B=%d\n", missing+0, diff+0, extra+0
}
' LISTB.txt LISTA.txt

Notes, pitfalls and improvements:

  • This assumes filenames have no spaces and the lists use the format shown. If filenames may contain spaces, the "last token" trick breaks — produce machine-friendly lists instead (use stat/find to emit fixed, delimited fields or epoch timestamps) and compare on those outputs.
  • ls -l sometimes shows a year instead of a time (for older files). For reliable timestamp comparisons use a consistent source such as file modification epoch seconds (stat) rather than the human ls field.
  • If you want content-level checks, compute checksums (md5sum/sha256sum) and compare those instead of size/time.
  • For more complex rules (recursive dirs, path normalization, large lists) consider a small Python or Perl script for clearer parsing and better error reporting.

This fills the gap left in the thread: concrete script plus practical caveats and ways to make comparisons robust and maintainable.

There is a huge amount of context missing here. For instance, are the lists always arranged such that the subset list (LIST A) is the first N items to appear in the full list (LIST B)?

Without any insight I'd suggest that the only thing you can base the difference on is the file name (all other fields are subject to change). This lends itself to some sort of structure based on the file name with elements of the structure being the attributes of the file. Using some scripting language (perl, ruby) to facilitate that you could easily sort the two lists and compare differences in sorted order (according to file name).

I'd certainly try to avoid to the epic shell one-liner - you'd only be inviting maintenance nightmares.

What have you tried so far and why is it not currently working?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.