Using awk to output matches between two files to one file and mismatches to two others


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using awk to output matches between two files to one file and mismatches to two others
# 8  
Old 08-27-2016
Interesting, I suspected maybe it was missing values, but couldn't understand why, if the values used in the lookup key have values, why the awk wasn't working properly. I guess why do all the columns need something in them. I will make sure my data is cleaner and my questions more precise. Thank you @RudiCSmilie
# 9  
Old 08-27-2016
Quote:
Originally Posted by cmccabe
Interesting, I suspected maybe it was missing values, but couldn't understand why, if the values used in the lookup key have values, why the awk wasn't working properly. I guess why do all the columns need something in them. I will make sure my data is cleaner and my questions more precise. Thank you @RudiCSmilie
The problem is that even though you said that your input files are tab separated, the sample files you provided here are separated by multiple spaces (and we have no way of knowing where an empty tab-separated field is when there are no tabs. (You may have noticed that your script had a -F'\t' that is missing in RudiC's script. With the sample data you provided (with no tabs), adding that -F'\t' would mean that every line in both sample input files would be a single field.)

If your real data really is tab separated, adding a -F'\t' to the start of RudiC's script might be all that you need.
# 10  
Old 08-28-2016
In fact, it was Yoda's flawlessly working script, and the field separator got lost in the OP's copy/paste action.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To get the exact mismatches from two csv files

Hello Guys, I am pretty new to unix shell scripting where in i need to compare two files which are comma separated files. So here i go with the file contents cty_id,grade_val,g_val_2,g_val_3 001,10,20,30 002,,,40 003,100,,10 grade_val,g_val_2,cty_id 10,20,001 41,,002 100,1,003... (4 Replies)
Discussion started by: Master_Mind
4 Replies

2. Shell Programming and Scripting

Using awk to output matches and mismatches between two files to one file

In the tab-delimited files, I am trying to match $1,$2,$3,$4,$5 in fiel1 with $1,$2,$3,$4,$5 in fiel2 and create and output file that lists what matches and what was not found (or doesn't match). However the awk below seems to skip the first line and does not produce the desired output. I think... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk to output specific matches in file

Using the attached file, the below awk command results in the output below: I can not seem to produce the desired results and need some expert help. Thank you :). awk -F'' ' { id += $4 value += $5 occur++ } END{ printf "%-8s%8s%8s%8s\n", "Gene", "Targets", "Average Depth", "Average... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Applying the same awk over a directory of files with individual file output

I am trying to apply an awk action over multiple files in a directory. It is a simple action, I want to print out the 1st 2 columns (i.e. $1 and $2) in each tab-separated document and output the result in a new file *.pp This is the awk that I have come up with so far, which is not giving me a... (6 Replies)
Discussion started by: owwow14
6 Replies

5. Shell Programming and Scripting

BASH - Compare 2 Files, Output All Matches

This is probably rehash but I did look. :rolleyes: I want a bash script that will take Item 1 in File1, traverse all lines in File2 and output if a match exists. Continuing the pattern recursively, Item2, File1, traverse all lines in File2 for a match, continue this pattern until all lines... (6 Replies)
Discussion started by: rcbarr2014
6 Replies

6. Shell Programming and Scripting

Compare 2 files and print matches and non-matches in separate files

Hi all, I have two files, chap.txt and complex.txt. chap.txt looks like this: a d l m r k complex.txt looks like this: a c d e l m n j a d l p q r c p r m ......... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

7. UNIX for Dummies Questions & Answers

Use awk to pipe output from one file into multiple files

Hi All. Thanks for your help in advance. I have a requirement to examine the number of delimiters in each record of a file. If the record has the expected number of delimiters it should be passed into a 'good' file. If it does not, the record should be passed into a 'bad' file. I have been able... (8 Replies)
Discussion started by: codestar1
8 Replies

8. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

9. Shell Programming and Scripting

Writing output into different files while processing file using AWK

Hi, I am trying to do the following using AWK program. 1. Read the input data file 2. Parse the record and see if it contains errors 3. If the record contains errors, then write it into Reject file, else, write into usual output file or display it on the screen Here is what I have done -... (6 Replies)
Discussion started by: vidyak
6 Replies

10. Shell Programming and Scripting

Matches and mismatches in perl

When we give an input sequence , the program should match with the pattern and give the matches and mismatches in the output. i will give you 2 small examples. if you cant get it pls let me know. i will try to give a clear idea. example 1: $a=APPLE; # let it be a pattern... (0 Replies)
Discussion started by: srisha
0 Replies
Login or Register to Ask a Question