ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
okay, i seem to have a problem with the search command which i used.
Code:
echo -n "Title:"
read Title
echo -n "Author:"
read Author
price_check=`grep $Title fruit | grep $Author | awk -F":" '
if [ "$price_check"="$Author" ] ; then
echo "book exist"
else
echo " Book does not exist"
fi
{print $3}'
for example, the user is to input title as "Persia" and "Author" as John. i will then use grep to search for lines which contain the title, then pipe it into another grep command which will then search for author based on the row available, then after that print $3 right?
but for some reason, when i did a check on it, it does not seem to work. when i input data which is not in the database, it still displays the message "book exist" instead of telling me "book does not exist".
What is the correct format or coding to be used to do a search based on two inputs?
You may also want to look at this line closely. The punctuation marks don't match up. In front of grep you have an acute, while at the end of the line you have a single quote.
Code:
price_check=`grep $Title fruit | grep $Author | awk -F":" '
Okay, am i correct to say that there should be a print $3 there as it is where the Author columm is? so basically, this is suppose to check for line which contain $title , then with that info, check for lines which contain $Author , and then with the row which we have , print out $2 which should be the price. the echo command will then show the price as an output right?
that is what i did, but nothing seems to be working.
could you show me an example how the if statement should be used. i tried out changing the location of the { from :
I can't relate your first question to the preceding discussion,
In the "price_check" statement, why do you have quotes on $Title and $Author? I think the resulting test would be--e.g.: Does the value of variable 3 equate to the literal string "$Author"
yes, that what i am trying to achieve. im trying to do a test to check if we are going to delete the information on the right row. i guess the best way to do it would be to run pull out a data from the row which you have specified and then compare it to the user input.
Do you know of any other ways in which i do this search?
Sorry---I am not connecting your answers with my questions....
Are you trying to compare the value of variable "3" with the literal string "$Author"? I don't think so---I think you want the value of the variable named "Author".
If I'm correct, then you want--e.g.: if ($3==$Author)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.