This is a test version of Biostars. For the public version, visit https://www.biostars.org.
grep extract command will remove replicates automatically

Dear all,

I have a file 1, containing many gene ID, and also has replicates for the gene ID. I want to extract the corresponding line from an gff file, I have a script can accomplish this, but this script will remove the replicates automatically, if I don't want to remove the replicates and want to keep the output just like the order in file 1, if there is anyway I could do this...

Here is file 1:

gene14184
gene25736
gene14184
gene8906
gene25736
gene14775
gene4224
gene8906
gene14184
gene24702

Here is the script I am using:

grep -Fwf file1.txt 001660625_genomic.gff > output.txt
rna-seq

I don't know if I really understand what you want to do, but try this:

(for ID in $(cat file1); do echo -e $ID"\t"$(grep $ID gff1); done;) > output.txt

1 answer

Solved!! and Vlookup in excel could also do this. Thanks!!

Excel can do many things, but once a file gets larger it will crash plus user interaction with it is irreproducable in terms of coding it up in a script. If it helped you this time it is fine but I strongly recommend to learn how to do things outside of Excel. Imagine one of the files was 10Gb in size...what then.

Log in to answer this question.