Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-20-2012
Registered User
 
Join Date: Dec 2011
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
script to match name with code?

I need a script that could take in a line from one file and match the line up with codes in the order file.

My first file, called names.txt ,contains:
>123456789
>987654321
>15946873
>157987513


The other file, called data,contains:
GB_00012.faa
GB_6789333.faa
GB_100098.faa
GB_1237700.faa


All the data files contain a line startin with ">" symbol, and contain after that point somwhere the names.txt identifier. Ideally I would love the output to be:
>123456789 GB_1237700.faa >line from GB file.

I know how to do it manually using grep, but having around 10000 different identifiers and three coupled files together, would take me ages to go through one by one. If this is possible to make in a script, I'd be really thankful for the help!
Sponsored Links
    #2  
Old 02-20-2012
neutronscott's Avatar
script kiddie
 
Join Date: Jun 2011
Location: Charleston, SC
Posts: 649
Thanks: 18
Thanked 189 Times in 179 Posts
Something like this may get you started:


Code:
#!/bin/bash
declare -a data_files=()
while IFS= read -r file; do data_files+=("$file"); done < "data"
while IFS='>' read -r _ code; do
        grep -H "$code" "${data_files[@]}"
done < "names.txt"

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pattern match .com in awk script shreeprabha Shell Programming and Scripting 2 05-11-2011 06:58 PM
how to convert a shell script to a php script for displaying next word after pattern match sb245 Shell Programming and Scripting 0 03-02-2011 01:42 AM
exact string match ; search and print match bash_in_my_head Shell Programming and Scripting 8 05-22-2010 11:41 PM
Need help to grep for a title match and then make some queries after the match leo.maveriick Shell Programming and Scripting 3 03-24-2010 03:18 PM



All times are GMT -4. The time now is 05:44 PM.