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.
i am having a small problem in extracting out the information from the database. For example, if i were to input a book titled rina into my search , i would only want it to display the row which has the title rina, like this
Code:
rina:fatin:20:20:20
but when i use a coding like this :
Code:
grep -i "$Title" fruit| awk -F":" '{ print $0}'`
its displays both titles and their information
Code:
rina lives:fatin:20:20:20
rina:fatin:20:20:20
for some reason, it will read both rows as both contains the word "rina". does anybody know how i can modify my statement to solve this problem?
okay, just to check, i tried using awk for this problem. so my coding was like this .
Code:
Title=
echo "read this:"
read Title
awk '/'$Title'/' fruit
but it also displays both strings. why does awk have the same problem also?
I believe you are missing a key concept. AWK displays both line because they both contain the keyword. That is why I used the ":" in my SED example.
With any regular expression (which includes keywords in plain english), the match is made if the pattern is found---it does not matter if there is also something else there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.