Joining of Commands.

Hello, i have a few questions which i hope you guys can address. the 1st prob:

The database i am using is a text file which displays the information like this :
Title : Quantity : Price
Persia : 30 : 20
Australia : 40 : 20

Number=
echo -n "Title : "
read Title
echo -n " Price : "
read Price
if grep -q"$Title" Hello1 | -q"$Price" Hello1 ; then   -- line 7
echo "A"
else 
echo "not there"
fi

What i am trying to do is that when it searches,both the information must be the same , then it will come out the output "A". For example, if i input "Persia" into Title and "20" into Price , only then will it display the output"A". When i ran this, an error like the one below came out.

 line 7: -q20: command not found

what is the problem with this and how do i solve it?

2nd problem : how can i make sure that when it searches for the information, it is from the correct row? as you can see from the database, both books have the same price.

3rd) After searching and getting the right row , how do i delete it?

What if you changed it to this:

if grep -q "$Title" Hello1 | grep -q "$Price" Hello1 ; then   #-- line 7

still the same problem. is it possible to use the Sed command to filter the information then delete it?

Change your if statement to:

if grep "$Title" Hello1 | grep -q"$Price" ; then

You were missing your grep command after the pipe, so the shell was trying to find a command called "-q20" and so it gave the error.

Also you should remove the first "-q" so that the output passes through the pipe for the next grep.

This will help the first problem but you will run into issues if you search for a $Price that equals the Quantity value. You will have to use awk or cut to check the position of the value to make sure you found the correct entry.

O could you give some guidance on how the awk code be like when I try to retreive data? For example when I search for apple, how do I get it to display all the information such as price and quantity?

Sure. Since your Price value is the 3rd field delimited by ":", then you could look it up this way:

# Lookup price
price_value=`grep $Title filename | grep $Price | awk -F":" '{print $3}'`

# Check if price_value matches $Price
if [ $price_value eq $Price ]
then
  # Print record
  echo "Found the following record that matched:"
  grep $Title filename | grep $Price
fi