Match working for some but not all


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match working for some but not all
# 1  
Old 06-26-2015
Match working for some but not all

I am not sure why the script below seems to pull the correct values for most, but not all. Basically what is supposed to result is the $1 value in genes.txt is matched to the $3 value in RefSeqGene.txt and the value in 6 field is copied. In the output below that is the case most of the time but not always and I'm not sure why. Thank you Smilie.


Code:
awk 'FNR==NR {E[$1]; next }$3 in E {print $3, $5}' genes.txt RefSeqGene.txt > update.txt

Output:
Code:
AAGAB NM_001271886.1
AANAT NM_001166579.1
AANAT NR_110548.1
AANAT NM_001088.2
AARS LRG_359  (should be NM_001605.2)
ABCC9 LRG_377 (should be NM_005691.2)
ABCC9 LRG_377 (should be NM_020297.2)
ABCC9 LRG_377 (should be NM_005691.3)
ABCC9 LRG_377 (should be NM_020297.3)

# 2  
Old 06-26-2015
Why do you print $5 if you want field 6? If you know the answer, you know the cause of the problem.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-26-2015
In addition change FS and OFS to \t for the 2nd file...

Code:
awk 'FNR==NR {E[$1]; next }$3 in E {print $3, $6}' genes.txt FS='\t' OFS='\t'  RefSeqGene.txt


Last edited by Scrutinizer; 06-26-2015 at 03:54 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 06-26-2015
I'm not sure why, but before I couldn't get it to work.... maybe I was typing something wrong. Thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

5. Shell Programming and Scripting

Search from 1st match and end 2nd match

I've been looking through the forums for awhile now and looking at the man page for grep and egrep and not seeming to find this scenario so it might not be possible but figured I'd throw it out to get some ideas. I'm looking for a way to search a file for 1st match (example below net self) and... (3 Replies)
Discussion started by: djzah
3 Replies

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

7. Shell Programming and Scripting

Match in perl not working with ARGV

Hi , I need to match module data_tx_dig ( I tried matching ~m/module(\s+)ARGV(\s+)\(/ --> (generic code)but is not working.The same is able to match when i provide hardcoded value instead of passing from the command line. ~m/module(\s+)data_tx_dig(\s+)\(/ -->(hardcoded code).Please help me... (8 Replies)
Discussion started by: dll_fpga
8 Replies

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

9. Shell Programming and Scripting

sed : match one pattern then the next consecutive second pattern not working

Ive used this snippet of code on a solaris box thousands of times. But it isnt working on the new linux box sed -n '/interface LoopBack0/{N;/ ip address /p;}' *.conf its driving me nuts !! Is there something Im missing ? (7 Replies)
Discussion started by: popeye
7 Replies

10. Shell Programming and Scripting

RegExp negative match not working

or I don't know how to make it work ... Hello im trying to build regexp that will match me single string or function call inside of brackets for example I have : <% myFunction("blah",foo) %> or <% myVar %> and not match : <% if(myFunction("blah",foo)==1) %> or <% while(myvar < 3){... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question