Off topic:how to fetch match string by comparing two files by using Shell or python
0
0
Entering edit mode
9.7 years ago
Raghav ▴ 100

Dear All,

I need your help to correct me.

I have two files named unique.txt and Total.txt.

unique.txt file contain two columns each columns are separated by tab. Total.txt file contain: 3 columns each column separated by tab.

What I do, take each rows from unique.txt file find that in total.txt file. If present then extract entire row from total.txt and save it in new output file new_out.txt.

To do this I use shell script

#!/bin/bash
FILE=$1
while read line; do
    egrep "$line" Total.txt > new_out.txt
done < $unique.txt

I know this is very poor attempt to resolve this problem. Please help me to improve it and reach up to optimal solution.

Please help out.

Unique.txt

mitochondria_205000_225000 mitochondria_195000_215000
mitochondria_345000_365000 mitochondria_335000_355000
mitochondria_345000_365000 mitochondria_5000_25000
chloroplast_115000_128207 chloroplast_35000_55000
chloroplast_115000_128207 chloroplast_15000_35000
mitochondria_185000_205000 mitochondria_25000_45000
2_16595000_16615000 2_16585000_16605000
4_2785000_2805000 4_2775000_2795000
4_11395000_11415000 4_11385000_11405000
4_2875000_2895000 4_2865000_2885000
4_13745000_13765000 4_13735000_13755000

Total.txt

interaction1 mitochondria_205000_225000 mitochondria_195000_215000
interaction2 mitochondria_345000_365000 mitochondria_335000_355000
interaction3 mitochondria_345000_365000 mitochondria_5000_25000
interaction4 chloroplast_115000_128207 chloroplast_35000_55000
interaction5 chloroplast_115000_128207 chloroplast_15000_35000
interaction15 2_10515000_10535000 2_10505000_10525000

Waiting for your valuable suggestions

python shell • 2.8k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1472 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