#!/bin/bash ## receives two filenames; returns TRUE iff 1st is leading-subset-of-or-equal-to 2nd; Eugene Reimer 2010-03; ## was a function in WEBGETLOGS, but may be useful elsewhere; CMPMSG=$(cmp $1 $2 2>&1) ##compare using cmp if [[ $CMPMSG == "" || $CMPMSG == "cmp: EOF on $1" ]];then exit 0; fi ##they're identical OR $1 is leading subset of $2, so indicate TRUE exit 99 ##otherwise indicate FALSE NOTES: ====== now using cmp on entire files w/o "-s" then checking its output for: emptystring (indicates EQUAL) or cmp's subset-msg which looks like: cmp: EOF on FILENAME, where we need to ensure that FILENAME names the $1 file; BEWARE: one kind of cmp-msg goes to stdout, the other goes to stderr==!!== my first thought (for the use in WEBGETLOGS) was to compare only first lines AND file-sizes, then realized a simpler test would also do a better job; Obsolete first version: sz1=$(ls -l $1 |arr 5); head -n1 $1 >/tmp/SubsetOrEqual-1 ##get filesize and isolate first line sz2=$(ls -l $2 |arr 5); head -n1 $2 >/tmp/SubsetOrEqual-2 if cmp -s /tmp/SubsetOrEqual-1 /tmp/SubsetOrEqual-2 && ((sz2>=sz1));then exit 0; fi ##first records match and $2 as big, so indicate TRUE exit 99 ##otherwise indicate FALSE