Sponsored Content
Full Discussion: Match in two files
Top Forums Shell Programming and Scripting Match in two files Post 302943857 by cmccabe on Wednesday 13th of May 2015 10:56:35 AM
Old 05-13-2015
Match in two files

Trying to match $5 of file1.txt to $1 of file2.txt and if there is a match copy $6 of file2.txt and paste it to $7 of file1.txt. My attempt is below but it does not seem to produce the desired output. Thank you Smilie.

Code:
 awk 'NR==FNR{A[$5]=$1; next}  A[$6]  {$6=$6 " " A[$7]}1' file2.txt file1.txt > match.txt

File1.txt
Code:
RefPrimer	ref	antiref	omosome	PrimerSet	SeqRxn	Link
AntirefPrimer	antiref	ref	omosome			
PXL-A0000005ref	69066	69311	1	PXL-A0000005	SeqRxn4	
PXL-A0000005antiref	69311	69066	1			
PXL-A0000007ref	69700	70033	1	PXL-A0000007	SeqRxn4	
PXL-A0000007antiref	70033	69700	1

File2.txt
Code:
PXL-A0000005	chr1	69066	69311	DTE3504500000005 https://www.xxxx.com/add_2_cart.php?catno=PXL-A0000005&storage=lyophilized&rxns=100&num=1&test=mixed&format=tube
PXL-A0000007	chr1	69700	70033	DTE3504500000007 https://www.xxxx.com/add_2_cart.php?catno=PXL-A0000007&storage=lyophilized&rxns=100&num=1&test=mixed&format=tube

Desired output
Code:
RefPrimer	ref	antiref	omosome	PrimerSet	SeqRxn	Link
AntirefPrimer	antiref	ref	omosome			
PXL-A0000005ref	69066	69311	1	PXL-A0000005	SeqRxn4	https://www.xxxx.com/add_2_cart.php?catno=PXL-A0000005&storage=lyophilized&rxns=100&num=1&test=mixed&format=tube
PXL-A0000005antiref	69311	69066	1 
PXL-A0000007ref	69700	70033	1	PXL-A0000007	SeqRxn4	https://www.xxxx.com/add_2_cart.php?catno=PXL-A0000007&storage=lyophilized&rxns=100&num=1&test=mixed&format=tube
PXL-A0000007antiref	70033	69700	1

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match the records in two files.

Hi all please give me the solution for this im stuck somewhere. I have two files A and B file A has 300 records as 000.aud 111.aud . . . 300.aud file B has 213 records randomly 005.aud 176.aud . . . 200.aud I want to match similar 213 records in file B from file A. (2 Replies)
Discussion started by: Haque123
2 Replies

2. UNIX for Advanced & Expert Users

Match two files

Hi, can any one please assist me, I tried doing diff file1 file2, but does not get the require output. File1: apple mango peas File2: carrot mango apple 123 Q. Match the two files such that, if any word present in file1, for ex peas, does not matches to file2 then it should go... (1 Reply)
Discussion started by: sureshcisco
1 Replies

3. Shell Programming and Scripting

List files only when a certain number of files match

Hi, I have many files named CCR20110720011001.CTRD CCR20110720011501.CTRD CCR20110720012001.CTRD CCR20110720012501.CTRD CCR20110720021001.CTRD ... (9 Replies)
Discussion started by: shadyfright
9 Replies

4. Shell Programming and Scripting

match 2 files by values

Hello ALL, Hope all fine for you. I have the following task but no idea about how to do. I have 2 files (ascii) one of them is a list of bib records, looks like this: =LDR 01228nam 2200301 b 4500 =001 00000000000001 =005 20090429:10082000 =008 ... (2 Replies)
Discussion started by: ldiaz2106
2 Replies

5. Shell Programming and Scripting

Match the columns between 2 files

I have two files I want to match ids in the 5th column of the file 1 with the first column of the file 2 and get the description for the matched ids as shown in the output sno nm no nm2 ID 1 cc 574372 yyyi |6810|51234| 2 bb 119721 nmjk |6810|51234|51179| ... (4 Replies)
Discussion started by: raj_k
4 Replies

6. Shell Programming and Scripting

Match in two files

grep -f genes.txt refseq_exons.txt grep -wFf genes.txt refseq_exons.txt > output.txt awk 'FNR==NR {a; next} $1 in a' genes.txt refseq_exons.txt > output.txt The above seem to match the records but not all of them and I'm not sure why., I am just trying to match the gene name in genes.txt to... (3 Replies)
Discussion started by: cmccabe
3 Replies

7. Shell Programming and Scripting

Text match in two files

Trying to match the text from file1 to file2 and print what matches in a new file (match.txt) and what does not in another (missing.txt). awk -F'|' 'NR==FNR{c++;next};c > 0' flugent.txt IDT.txt > match.txt Thank you :). (8 Replies)
Discussion started by: cmccabe
8 Replies

8. Shell Programming and Scripting

New files based off match or no match

Trying to match $2 in original_targets with $2 of new_targets . If the two numbers match exactly then a match.txt file is outputted using the information in the new_targets in the beginning 4 fields $1, $2, $3, $4 and value of $4 in the original_targets . If there is "No Match" then a no... (2 Replies)
Discussion started by: cmccabe
2 Replies

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

10. 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
DIFF(1) 						      General Commands Manual							   DIFF(1)

NAME
diff - print differences between two files SYNOPSIS
diff [-c | -e | -C n] [-br]file1 file2 OPTIONS
-C n Produce output that contains n lines of context -b Ignore white space when comparing -c Produce output that contains three lines of context -e Produce an ed-script to convert file1 into file2 -r Apply diff recursively to files and directories of EXAMPLES
diff file1 file2 # Print differences between 2 files diff -C 0 file1 file2 # Same as above diff -C 3 file1 file2 # Output three lines of context with every diff -c file1 file2 # Same diff /etc /dev # Compares recursively the directories /etc and /dev diff passwd /etc # Compares ./passwd to /etc/passwd DESCRIPTION
the same name, when file1 and file2 are both directories" difference encountered" Diff compares two files and generates a list of lines telling how the two files differ. Lines may not be longer than 128 characters. If the two arguments on the command line are both directories, diff recursively steps through all subdirectories comparing files of the same name. If a file name is found only in one directory, a diagnostic message is written to stdout. A file that is of either block special, character special or FIFO special type, cannot be compared to any other file. On the other hand, if there is one directory and one file given on the command line, diff tries to compare the file with the same name as file in the directory directory. SEE ALSO
cdiff(1), cmp(1), comm(1), patch(1). DIFF(1)
All times are GMT -4. The time now is 11:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy