This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Select number for each region

Hello

I have some regions in one column(.txt) such as :

    chr1:10041971-10153500
    chr2:2644661-293334
    chr2:32120816-32177000    
    chr20:27254237-27374800
    chr10:706059-1034630
    chr3:215840607-215890726
    chr5:4353812-4477220

Also I have a list include 2 columns like :

    1 chr1:10041971-10153500
    2 chr1:10745944-10994508
    3 chr2:2644661-293334
    4 chr2:1701982-1957905
    5 chr2:32120816-32177000
    6 chr20:28283821-28420685
    7 chr20:27254237-27374800
    8 chr11:54281056-54342856
    9 chr10:706059-1034630
    10 chr3:215840607-215890726
    11 chr5:4353812-4477220
    12 chr20:27154237-27374041

I just need to have an output include the numbers( for each region in the input) that exists in the list, out put should be like:

1
3
5
7
9
10
11

Thanks.

genome

Hello hosein_salehi6!

We believe that this post does not fit the main topic of this site.

Basic text processing question, not really bioinformatics. Please search StackOverflow

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

1 answer

cat file1.txt

chr1:10041971-10153500
chr2:2644661-293334
chr2:32120816-32177000    
chr20:27254237-27374800
chr10:706059-1034630
chr3:215840607-215890726
chr5:4353812-4477220

cat file2.txt

1 chr1:10041971-10153500
2 chr1:10745944-10994508
3 chr2:2644661-293334
4 chr2:1701982-1957905
5 chr2:32120816-32177000
6 chr20:28283821-28420685
7 chr20:27254237-27374800
8 chr11:54281056-54342856
9 chr10:706059-1034630
10 chr3:215840607-215890726
11 chr5:4353812-4477220
12 chr20:27154237-2737404

awk 'NR==FNR{a[$1]++;next};a[$2]' file1.txt file2.txt | awk '{printf "%s ", $1} END {print ""}'

1 3 5 7 9 10 11

Log in to answer this question.