The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 11-19-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
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