# script problems

**URL:** <https://community.unix.com/t/script-problems/150711>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [November 29, 2004, 9:56pm UTC](https://community.unix.com/t/script-problems/150711 "2004-11-29T21:56:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellsd](https://community.unix.com/letter_avatar/hellsd/32/5_5575768a8748004e209b776fc1b2916d.png) [@hellsd](https://community.unix.com/u/hellsd)\
**Post date:** [November 29, 2004, 9:56pm UTC](https://community.unix.com/t/script-problems/150711/1 "2004-11-29T21:56:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zazzybob](https://community.unix.com/user_avatar/community.unix.com/zazzybob/32/112_2.png) [@zazzybob](https://community.unix.com/u/zazzybob)\
**Post date:** [November 30, 2004, 5:01am UTC](https://community.unix.com/t/script-problems/150711/2 "2004-11-30T05:01:22Z")

</div>

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

```nohighlight
#!/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

---

<div class="post-metadata">

**Author:** ![hellsd](https://community.unix.com/letter_avatar/hellsd/32/5_5575768a8748004e209b776fc1b2916d.png) [@hellsd](https://community.unix.com/u/hellsd)\
**Post date:** [November 30, 2004, 12:56pm UTC](https://community.unix.com/t/script-problems/150711/3 "2004-11-30T12:56:32Z")

</div>

Thanks, works like magic.

---

<div class="post-metadata">

**Author:** ![hellsd](https://community.unix.com/letter_avatar/hellsd/32/5_5575768a8748004e209b776fc1b2916d.png) [@hellsd](https://community.unix.com/u/hellsd)\
**Post date:** [June 13, 2005, 8:17pm UTC](https://community.unix.com/t/script-problems/150711/4 "2005-06-13T20:17:01Z")

</div>

what is with the fgrep? will run faster?
