Help with Comparing 2 strings from text

Hey guys how do I compare 2 strings from the text file,
and check for duplication?
For example, I add an item call Laptop, it will record to the textfile call file.
If it detects duplicate it will say the record record exist?

file.txt contains

Laptop:Sony:1000
Phone:Apple:30

A head start would be fine for me, cuz I'm kinda new to shell scripting.

Have a look here

I made a function something like this, I stored the extracted data in c1 but I can't compare both of the strings. Am I doing it wrong?

c1=`grep -w $title data.txt |grep -w $author|wc -l`
I wonder if this is correct..

function add_new_book
{
    echo "1) add_new_book"
	echo "Title: "
	read title
	echo "Author: "
	read author
	c1=`grep -w $title data.txt |grep -w $author|wc -l`
if [ $c1 -ne 0 ]
then
	echo "Price: "
	read price
	echo "Qty Available: "
	read qtyA
	echo "Qty Sold: "
	read qtyS
	echo "$title author price qtyA qtyS" >> data.txt
	echo "New book title "$title" added successfully!"
else
   echo " Name not Found"
fi
	
}

@aLHaNz
c1 variable is holding a numeric value after all
the following code fragment

c1=`grep -w $title data.txt |grep -w $author|wc -l`

in simple speaking it says extract the lines that contains the value stored in the variable $title as a word then refine this extracted lines with another filter against the value stored in the variable $author then pass the out to some sort of line counter that what it says in final $c1 will hold a numeric value if conditions of combined filters are met.

I see no logical errors in the function

add_new_book

.
Also I see no string comparison in the snippet you sent except the pattern matching logic

hmmm ok..
So how do I compare both of the input of what the user want and the data in the text file?
Lets say user enter the title and author.
If it detects the same author it will say book existed? :confused: