[SOLVED] Why is grep output file the same as original search file?
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!
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.
Why is grep output file the same as original search file?
I'm trying to extract the contents of one file (infile.txt) from another file (mainfile.fastq). I'm using the command:
$ grep -f infile.txt mainfile.fastq
In the terminal, the complete contents of mainfile.fastq are shown, with the matching lines from infile.txt highlighted.
If I try to output matching lines, I get the complete contents of mainfile.fastq:
$ grep -f infile.txt mainfile.fastq >out.txt
I'm trying to get this to work so I can use a modified command on a larger file along with -A to extract trailing context as well. The output will be too much to read in the terminal.
Here are the contents of my infile.txt:
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/70114/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/6850/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/22749/ccs
In the terminal window, I get the full mainfile.txt with matching lines highlighted:
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/49/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/2229/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/22449/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/149/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/2802/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/20/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/749/ccs @m130129_192343_42154_c100435262550000001523067002011393_s1_p0/70114/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/6850/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/11523/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/81245/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/27245/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/1634/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/959/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/15423/ccs
@m130129_192343_42154_c100435262550000001523067002011393_s1_p0/834/ccs
Amani - Would that allow me to output lines that are the same between files? And is there an option for including trailing information, similar to grep -A? My end goal is not just to extract lines that are the same, but to use the infile to extract additional information from a mainfile.
Amani - Would that allow me to output lines that are the same between files? And is there an option for including trailing information, similar to grep -A? My end goal is not just to extract lines that are the same, but to use the infile to extract additional information from a mainfile.
Is it not possible with the
--LTYPE/GTYPE-line-format=... options?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.