Problem in extraction of values from a list
3
0
Entering edit mode
7.4 years ago
Vinay Singh ▴ 50

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.

grep vlookup perl • 1.5k views
ADD COMMENT
3
Entering edit mode
7.4 years ago
for gene in `cat file1`;
do
grep -w $gene file2 >> output.txt
done
ADD COMMENT
0
Entering edit mode

Thank you @WouterDeCoster i got the desired result.

ADD REPLY
0
Entering edit mode

Glad to help. I moved my comment to an answer so you can accept it and mark this question as solved.

ADD REPLY
0
Entering edit mode
7.4 years ago

I believe the following does the trick:

grep -w -f <(cut -f1 sheet1) Sheet2 > tadaaam.txt
ADD COMMENT
1
Entering edit mode

with option -w

ADD REPLY
0
Entering edit mode

Right, don't want to find gene22. I adapted my answer.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode
7.4 years ago
Vinay Singh ▴ 50

for gene in cat file1; do grep -w $gene file2 >> output.txt done The shell script provided by WouterDeCoster solved my problem. Thank you.

ADD COMMENT

Login before adding your answer.

Traffic: 2006 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6