script to match name with code?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers script to match name with code?
# 1  
Old 02-20-2012
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! Smilie
# 2  
Old 02-20-2012
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"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. UNIX for Dummies Questions & Answers

Code for exact match to count occurrence

Hi all, I have an input file as below. I would like to count the occurrence of pattern matching 8th field for each line. Input: field_01 field_02 field_03 field_04 field_05 field_06 field_07 field_08 TA T TA T TA TA TA... (3 Replies)
Discussion started by: huiyee1
3 Replies

5. Shell Programming and Scripting

Match pattern1 in file, match pattern2, substitute value1 in line

not getting anywhere with this an xml file contains multiple clients set up with same tags, different values. I need to parse the file for client foo, and change the value of tag "64bit" from false to true. cat clients.xml <Client type"FIX"> <ClientName>foo</ClientName>... (3 Replies)
Discussion started by: jack.bauer
3 Replies

6. Shell Programming and Scripting

Pattern Match Script

Hi, I have a requirement in which I have to search the File name for pattern and if the pattern matches then I will have generate a value. Example: If $File_name='*NF' Then "NBC" Else $File_Name='SC*' Then "CBS" Else "FB" fi What is the best way to do this? I want to pass the... (6 Replies)
Discussion started by: btt3165
6 Replies

7. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

8. Shell Programming and Scripting

script that can do a pattern match

Hi, str1="Hello World" CheckPattern="drW" Need a search function that will do a character search. and return me which charater($CheckPattern) is not matched in $str1. Thanks in advance Madhu (1 Reply)
Discussion started by: madhuti
1 Replies

9. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies
Login or Register to Ask a Question