I am trying to count the number of matched terms from an input list containing one term per line with a data file and create an output file containing both the matched (grep'd) term with the number of matched terms and where there isn't match, to return a value of zero. 

Input list:

```
+ 5S_rRNA
+ 7SK
+ AC001
+ AC000111.3
+ AC000111.6

```

The data.txt file:

```
chr10   101780038   101780209   5S_rRNA
chr10   103578280   103578430   5S_rRNA
chr10   112327234   112327297   5S_rRNA
chr10   120766459   120766601   7SK
chr10   127408228   127408317   7SK
chr10   127511874   127512063   AADAC
chr10   14614140    14614294    AC000111.3

```

I would like to create an output file containing all the unmatched terms and matched terms with the corresponding count to look like this:

```
+ 5S_rRNA   3
+ 7SK   2
+ AC001 0
+ AADAC 1
+ AC000111.3    1
+ AC000111.6    0

```

I can create an output file containing matched terms and the counts but I don't know how to get the zero value to be returned if there isn't a match and get it to print all the output to a separate file.
These are the codes I have used to create matched terms (thanks perreal and Mark Setchell)

```
#!/bin/bash
 while read line
do
   line=${line##+ }       # Strip off leading + and space
   n=$(grep "$line" data.txt 2> /dev/null | wc -l)
   if [ $n -gt 0 ]; then
      echo $line 
      echo $n
       fi
 done < input_list.txt > output.txt

```

and

```
cut -d' ' -f2 input.txt | grep -o -f - data.txt | sort | uniq -c | \
  sed 's/\s*\([0-9]*\)\s*\(.*\)/+ \2\t\1/' > output.txt

```

Any suggestions would be great. Thanks
Harriet