script to match name with code?

Thread Tools Search this Thread
# 1  
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:

The other file, called data,contains:

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  
Something like this may get you started:

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"


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. Shell Programming and Scripting

Display match or no match and write a text file to a directory

The below bash connects to a site, downloads a file, searches that file based of user input - could be multiple (all that seems to work). What I am not able to figure out is how to display on the screen match found or no match found" and write a file to a directory (C:\Users\cmccabe\Desktop\wget)... (4 Replies)
Discussion started by: cmccabe
4 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 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 - 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

Featured Tech Videos