awk arrays comparing multiple columns across two files.
Hi, I'm trying to use awk arrays to compare values across two files based on multiple columns. I've attempted to load file 2 into an array and compare with values in file 1, but success has been absent. If anyone has any suggestions (and I'm not even sure if my script so far is on the right lines) it would be very much appreciated.
file1
file2
Essentially, if column 2 in file 1, and column 4 in file 2 match, continue.
Then, if column 2 in file 2 is >= column 3 in file 1
and column 3 in file 2 is <= column 4 in file 1
print out matching line of file 1, and column 1,2 and 3 from file2.
Desired output
Using a pseudo script based on similar problems online, I've got:
This does a fantastic job of printing out the contents of file 2. Alas it's not what I was after. Any help would be much appreciated.
Thanks, that worked a treat. Had a little play around with that code, and realised one of the issues with my initial code was the use of new lines in inappropriate places. If I put a line between the awk 'NR==FNR and the rest of your code, that just prints out file 2 as well.
A valuable lesson that I'd previously overlooked. Thanks for your help.
Hello All;
I have two files with below conditions:
1. Entries in file A is missing in file B (primary is field 1)
2. Entries in file B is missing in file A (primary is field 1)
3. Field 1 is present in both files but Field 2 is different.
Example Content:
File A
... (4 Replies)
Hi all,
I have two files as below. I need to compare field 2 of file 1 against field 1 of file 2 and field 5 of file 1 against filed 2 of file 2. If both matches , then create a result file 1 with first file data and if not matches , then create file with first fie data. Please help me in... (12 Replies)
So I have a space delimited file that I'd like to split into multiple files based on multiple column values.
This is what my data looks like
1bc9A02 1 10 1000 FTDLNLVQALRQFLWSFRLPGEAQKIDRMMEAFAQRYCQCNNGVFQSTDTCYVLSFAIIMLNTSLHNPNVKDKPTVERFIAMNRGINDGGDLPEELLRNLYESIKNEPFKIPELEHHHHHH
1ku1A02 1 10... (9 Replies)
Hi
I have 2 files as below
File 1
Chr Start End
chr1 120 130
chr1 140 150
chr2 130 140
File2
Chr Start End Value
chr1 121 128 ABC
chr1 144 149 XYZ
chr2 120 129 PQR
I would like to compare these files using awk; specifically if column 1 of file1 is equal to column 1 of file2... (7 Replies)
hi everyone!
I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is:
awk 'NR==FNR{a=$2; next} {print a, $2}' file1 file2
I added the file3, file4 and... (10 Replies)
hi everyone!
I already posted it in scripts, I'm sorry, it's doubled
I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is:
awk 'NR==FNR{a=$2; next}... (1 Reply)
Hi Guyz
The 1st column of the input file has repeated keys like x,y and z.
The ist task is if the 1st column has unique key (say x) and then need to consider 4th column, if it is + symbol then subtract 2nd column value with 3rd column value (we will get 2(10-8)) or if it is - symbol subtract 3rd... (3 Replies)
Hi all,
I have three files, one is a navigation file, one is a depth file and one is a file containing the measured field of gravity. The formats of the files are;
navigation file:
2006 320 17 39 0 0 *nav 21.31542 -157.887
2006 320 17 39 10 0 *nav 21.31542 -157.887
2006 320 17 39 20 0... (2 Replies)