I have two files genelist.txt and data.txt. genelist.txt simply contains a single column of ~500 gene names, whereas data.txt is a tab delimited file that contains ~1000 columns (the samples) and ~30,000 rows (gene names). The general scheme of data.txt is outlined below.    Sample 1    Sample 2    Sample 3    Sample 4Gene A1.041.811.920.45Gene B1.111.121.320.92Gene C0.720.710.851.12Gene D1.191.420.130.32I need to extract each row (the entire row, i.e. all samples) from data.txt containing each of the ~500 gene names in genelist.txt and have these rows extracted to a seperate file. I've been told to use grep or awk and have looked into how to do this, however as a simple biologist with little/no coding experience I'm having a bit of trouble. Would it be possible for someone to explain how this is done, and hopefully provide some code for me to get underway.It would also be neat if the extraction returned only terms that match the entire gene name in genelist.txt. For example, if I had ABC123 but not ABC1234 in genelist.txt, I would want only ABC123 to be extracted and not ABC1234.Furthermore, after this is done how would I then check to see which of my genes from genelist.txt were not included in the extraction? (i.e. some genes may be incorrectly named, so I would have to go back and re-extract them with their alternative and/or correct name).Thanks very much for your time and help.
Basic grep/awk help - extracting all lines containing a list of terms from one file into a seperate file
awk;grep
To extract the lines from data.txt with the genes listed in genelist.txt:grep -w -F -f genelist.txt data.txt > newdata.txtgrep options used:-w tells grep to match whole words only (i.e. so ABC123 won't also match ABC1234).-F search for fixed strings (plain text) rather than regular expressions-f genelist.txt read search patterns from the fileIf you want the header (Sample 1, Sample 2, etc) line as well:grep -w -F -f genelist.txt -e Sample data.txt > newdata.txt-e Sample also search for SampleTo find lines in genelist.txt that aren't in newdata.txt:grep -v -w -F -f <(sed -E -e 's/(\t|  +).*//' newdata.txt) genelist.txt-v invert the search, print non-matching lines.The rest of the grep options are the same, but instead of using a file with the -f option, it's using something called Process Substitution (See also), which allows you to use a command in place of an actual file.  Whatever output the command creates is treated as the file's contents.In this case, we're using the command sed -E -e 's/(\t|  +).*//' newdata.txt, which outputs each line of newdata.txt after first deleting everything from either the first TAB character or the first pair of spaces it sees.  In other words, the first field (e.g. Gene A).  I had to use TAB or double space because a) i wasn't sure if your data was space-separated or TAB separated and b) the first fields in your example contained spaces.sed options used:-E use extended regular expressions, so we can use plain (, ), and + which are more readable than having to escape them with \ as \(, \), \+.-e 's/(\t|  +).*//' specifies the sed script to apply against the input (newdata.txt)Running that command on your sample data.txt would produce the following output:$ sed -E -e 's/(\t|  +).*//' data.txtGene AGene BGene CGene DAnyway, the output of that sed command is used as the list of search patterns by the grep command.