script problems

Hi,

Here is an example of a problem I have:

File2: contain the following lines:
a^ aaa^aa aa^~
b^ bbb^bb bb^~
c^ ccc^cc cc^~
d^ dddd^dd dd^~

File1: contain the following lines:
b^ bbb^bb bb^~
c^ ccc^cc cc^~

I get File2 as input and I want to do as following:

for each line in file2 {
if (line exist in file1) print "! "line
>> output
else
print "+ "line >> output
}

I work on tcsh script:
and this is what I wrote:

cat File2 | awk -F"^" '{if (grep -c $0 file1 == 0) print "- "$0 >> output
else print "! "$0 >> output}'

Expected output:

  • a^ aaa^aa aa^~
    ! b^ bbb^bb bb^~
    ! c^ ccc^cc cc^~
  • d^ dddd^dd dd^~

But I get:
! a^ aaa^aa aa^~
! b^ bbb^bb bb^~
! c^ ccc^cc cc^~
! d^ dddd^dd dd^~

Any idea?

Thanks,
Bando.

As long as some lines are not subsets of others, something like

#!/bin/sh

while read line
do
  # change to fgrep "$line" if required
  grep -F "$line" file1 >/dev/null 2>&1
  if [ "$?" -eq "0" ]; then
    echo "! $line"
  else
    echo "- $line"
  fi
done < file2

should work

Cheers
ZB

Thanks, works like magic.

what is with the fgrep? will run faster?