um, you need to read the man pages.
what you are trying to do above is search for the string "MSENGNKNIAIVEAFSETDKKTGEVVTLVPNTNNTVQPVALMRLGLFVPTLKSTSRGRKGQMVSMDASAELKQLSLAKAEGYEDIRISGLRLDMDNDFKT WVGIIHAFAKHKVVGDTVTLPFVEFVRLCGIPTARSSAKLRKRLDSSLSRIATNTISFRSKGSDEFYVTHLVQTAKYSVKHDTVELKADPKIFELYQFDK KVLLQLRAINELSRKESAQALYTFIESLPPDPAPISLARLRARLNLTSRTITQNATVRKAMEQLREIGYLDYTEVKRGNSVYFVIHYRRPKLRQAQISTK IDNDETEYSLPDENQDDIIDVVPDEKEGKMVMLSKEELALLEELRKAKTRK" in file_1.txt |
Quote:
I suppose I effectively want to say: "Find this record from file_1.txt in file_2.txt and then copy that line and the next few lines until a ">CDS.*" is encountered." |
What schneidz wanted to say is that you mixed up the files. You search patterns from file_2 in file_1 instead the other way around. The filename after -f should be the one with what you want to search, while the other one is the one in which you want to search.
|
Quote:
However, if I switch things around, where I'm searching for fgrep -f FileIWantToSearch FileWithinWhichToSearch, I get a blank text file again. I've tried it both ways round and always get a blank text file. |
Okay guys, thanks ever so much for your help! It has been much appreciated. My apologies for my idiocy at points, but I have solved it myself now with the following command:
Code:
for i in `cat file_1.txt`; do grep $i file_2.txt -A 1; done |
Hm, it seems that there are trailing lines in your file_1.txt. That's why the grep -f did not work. It assumed the spaces are part of the pattern to search. If you remove the spaces, it should work.
Edit: I meant "trailing spaces", of course, not "trailing lines" |
This is also incorrect in several ways.
Code:
for i in `cat file_1.txt`; do grep $i file_2.txt -A 1; done 2) Useless Use Of Cat. Although in this case it's really part and parcel of #1. 3) QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later. http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes 4) In addition, while not wrong, per se, $(..) is highly recommended over `..`. Backticks are deprecated syntax. Code:
while IFS='' read -r entry ; do grep -f is probably still the best option, however, although you need to be sure the matching patterns are exact, as millgates mentioned. Another thing to watch out for is that your files shouldn't have dos-style line endings. The extra carriage return would generally make matches fail. |
All times are GMT -5. The time now is 09:16 AM. |