March 28, 2024, 03:52:15 PM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Searching a database  (Read 3645 times)

Offline gregarion

  • New Member
  • Posts: 1
Searching a database
« on: January 14, 2010, 02:55:30 PM »
Hey guys, i have a database which is saved as a text file like this
Code:
Code: [Select]
Persia:42:John      ---database
France:50:Mabel
Persia:50:Rach
Germany:60:John
What i am trying to do is to do a search based on two inputs. (1)Title, (2) Author.

Code:

Code: [Select]
echo -n "Title:"
read Title 
echo -n "Author:"
read Author

price_check=`awk  -F: '{if ($1== "$Title" && $3== "$Author" ) print $2 } ' fruit`
echo $price_check
what i am trying to do is that, when i input for example Persia for $Title and Rach for $Author , i would like the code to print the price and save it into a variable and then display it with the echo command.

But for some reason, it is not seem to be working, is there something wrong with my coding?'

hope you guys can suggest other ways in which i can do a search with the two input.

Offline bilkay

  • Linux Noob !
  • *
  • Posts: 4
Re: Searching a database
« Reply #1 on: January 20, 2010, 10:47:01 PM »
Put single quotes around $Title and $Author (inside the double quotes).