Hi.
It's useful to see different approaches. I like the
awk solutions. The shell loop solution is also good, but will call
grep for each line, possibly a drawback for long files.
Here is a solution using *nix commands, although a modern shell is required for the process substitution, "<( ... )". This may be useful if it is not appropriate or possible to use
awk,
perl, etc.:
Code:
#!/usr/bin/env bash
# @(#) s1 Demonstrate feature.
set -o nounset
echo
debug=":"
debug="echo"
## Use local command version for the commands in this demonstration.
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash sort cut comm sed
echo
echo " Input file data1:"
cat data1
echo
echo " Input file data2:"
cat data2
echo
echo " Results:"
comm -23 <( sort data1 ) <( cut -d/ -f4 data2 | sort ) |
sed -e 's/^/ No entry for: /'
exit 0
Produces, using summer_cherry's datasets:
Code:
% ./s1
(Versions displayed with local utility "version")
GNU bash 2.05b.0
sort (coreutils) 5.2.1
cut (coreutils) 5.2.1
comm (coreutils) 5.2.1
GNU sed version 4.1.2
Input file data1:
data01
data02
data03
data04
data05
Input file data2:
/vol/vx/data01
/vol/vx/data02
/vol/vx/data05
Results:
No entry for: data03
No entry for: data04
See man pages for details ... cheers, drl