Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
just an e.g. i have two files, in one file (top.txt) 1000 random words are present which i want to use. In second file (All.txt), i have the 10000 words and their meanings in two fields. Now, what i want to do is that i want to use the output of my top.txt file in a way that after greping the words from top file i get the meaning of all those words from my other file All.txt. if i use the command % grep -e "(foul|.....|zeal) top.txt i grep all the words but now how to compare it with the other file. Kindly let me know
As grail said. Vague questions tend to get you vague answers, and one concrete example is worth a thousand lines of explanation. Show us a sample of each file, at least, along with what you want the output to look like.
But in any case, it's possible to use a file as a collection of patterns to search for. As long as the first file has only a single search word per line, you can try this:
grep -f top.txt All.txt
You can also use other options like -F, to search for fixed strings only, and -i to make them case-insensitive. See the grep man and info pages for more options.
Not that it really changes anything from the above other than bypassing the need for a tempfile. It still requires two grep processes. If we knew more about the actual requirements, perhaps we could even come up with a single-step solution.
Also be aware that P.S. is a bash-only extension.
PS: You need grep -E/egrep for a complex regex like that.
Last edited by David the H.; 10-21-2011 at 08:14 AM.
Thankyou so much for the solutions but its not working. I will try to elaborate by giving more examples.
This file contains 10 words
Second file all.txt
this file contains 26words with their codes, now what i want to do is to relate the top file words with the codes in all.txt files omiting the words which are not present in the top file. that is i want the result to look like this
two things important firstly words are not arranged alphabetically and secondly they are not case sensitive that is similar words might be in small alphabet in top file where as in capital in all file.
I hape i have given the clear e.g. now
your example still needs a bit more explanation. What happens with multiple matches? Do you want to keep the first match or the last match? Or maybe something else? Your sample output suggests that you want to print only the last match.
Its still not working. No i dont have multiple matches and i have single word in all.txt file with a single code no repeatation in the top.txt or all.txt files. Since i am a new user so if possible do guide me about using commands as well. Thankyou so much for your answers.
I am sorry for it. I have changed the repeated word, if any more repeatation then i wish to keep the first match. Well, i tried the commands but in top.txt file i didnt get any codes after my words with out any errors. I checked all.txt file as well but it remained same, and no new file was created as well.