Thank you @WouterDeCoster i got the desired result.
I have a list of gene ID in two subsequent columns, we can not shuffle the order of gene id as they are duplicated pairs and we want to insert chromosomal location from another sheet.
Example: sheet1
listA list B
gene2 gene4
gene10 gene19
gene17 gene20
........... ............
Sheet2
Start End
chromosome1 10234 10692 gene2
chromosome1 20786 21344 gene17
......................................................... .........................................................
Now I want Start and end position of list A genes in that order.
Please help me this.
3 answers
for gene in `cat file1`;
do
grep -w $gene file2 >> output.txt
done
Glad to help. I moved my comment to an answer so you can accept it and mark this question as solved.
I believe the following does the trick:
grep -w -f <(cut -f1 sheet1) Sheet2 > tadaaam.txt
with option -w
Right, don't want to find gene22. I adapted my answer.
Thank for your reply actually i tried grep -wFf file1 file2 In which file1 contains the listA and file2 contains sheet2, but in result i got the sorted result means the listA gene order in not preserved which i want in my case.
for gene in cat file1;
do
grep -w $gene file2 >> output.txt
done
The shell script provided by WouterDeCoster solved my problem.
Thank you.
Log in to answer this question.