awk to lookup section of file in a range of another file
In the below, I am trying to lookup $1 and $2 from file1, in a range search using $1 $2 $3 of file2. If the search key from file1 is found in file2, then the word low is printed in the last field of that line in the updated file1. Only the last section of file1 needs to be searched, but I am not sure how to do this or if I am on the right track. The last section of file1 is Missing in IDP but found in Reference: and only the lines in this section need to be searched (in this example there are 2 lines). Both files are tab-delimited as well. Thank you .
file1
file2
desired output
awk
Last edited by Don Cragun; 09-10-2016 at 12:51 PM..
Reason: added details, fixed format
I think some more information would have given added by you into your post, like as follows:
i- Is value of field2 is going to be always lesser than field3's value?(though I have considered both the cases into my code following)
ii- You have mentioned about last section of Input_file1 as Missing in Reference but found in IDP:, so do you mean by last column? Sorry I couldn't get it, so I didn't keep this point into my code.
iii- Could you please let us know if we need to update the Input_file1 itself here?
As a start we could try following code, if you could specify more clearly about your requirements, I would like to help more on this please.
Output will be as follows.
Thanks,
R. Singh
Last edited by RavinderSingh13; 09-10-2016 at 12:30 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
i- Is value of field2 is going to be always lesser than field3's value?(though I have considered both the cases into my code following)
- yes field2 will always be less than field 3
Quote:
ii- You have mentioned about last section of Input_file1 as Missing in Reference but found in IDP: , so do you mean by last column? Sorry I couldn't get it, so I didn't keep this point into my code.
-in file1 there are 3 sections or headers
- only the last section needs to be searched and the other two sections can be skipped. Each section ends with a :
Quote:
iii- Could you please let us know if we need to update the Input_file1 itself here?
- yes, if the file1 can be updated in-place that would be helpful. Maybe through redirection?
There is still a missing piece to the puzzle. The field 1 values in the 3rd section of file1 are 2 and 7 neither of which are equal to any field 1 values in file2 (chr2 and chr7).
If field 1 string equality is not required for a match; what are the rules for determining whether or not a line in file1 matches a line in file2? If field #1 supposed to be ignored and just look for field #2 values in file1 being between field #2 and #3 on any line in file2?
This User Gave Thanks to Don Cragun For This Post:
I didn't even realize that the $1 values were formatted differently between the two files. In this case, since $1 will always not be equal, then field #2 values in file1 being between field #2 and #3 on any line in file2 should be used. These values should be unique. Also, if a match (or near match) is found it prints "low" if no match (or near match) is found then "not low" is printed. Thank you .
Last edited by cmccabe; 09-10-2016 at 03:01 PM..
Reason: added details
I use conditional operators alot in AWK to print rows from large text files based on values in a certain column. For example:
awk -F '\t' '{ if ($1 == "A" || $1 == "C" ) print $0}' OFS="\t" file1.txt > file2.txt
In this case every row is printed from file1 to file2 for which the column 1... (5 Replies)
I am trying to update the below awk, kindly provided by @RavinderSingh13, to update each line of file1 with either Low or No Low based on matching $2 of file1 to a range in $2 and $3 of file2. If the $2 value in file1 matches the range in file2 then that line is Low, otherwise it is No Low in the... (3 Replies)
The below awk uses $3 and $4 in search as the min and max, then takes each $2 value in lookup and compares it. If the value in lookupfalls within the range in searchthen it prints the entire line in lookup/ICODE]. What I can't seem to figure out is how to print the matching $5 from search on that... (4 Replies)
have written a combined sed+awk to perform a lookup operation which works but looking to enhance it.
looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so:
cat foo
make,model,engine,trim,value... (6 Replies)
I have the below 2 files:
1) Third field from file1.txt should be compared to the first field of lookup.txt.
2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt.
3)Else just print the line from file1.txt.
File1.txt:... (4 Replies)
I have a list of Servers in no particular order as follows:
virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection).
9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
I want to lookup filea with fileb,filec and filed.
If entry in filea exist in fileb and filec mark Y and then if entry in filea exist in filed mark as Y.
Final output should have all the entries from filea.
This prints only matching entries from file a in fileb i want all entries from... (9 Replies)
Write a quick shell snippet to find all of the IPV4 IP addresses
in any and all of the files under /var/lib/output/*, ignoring
whatever else may be in those files. Perform a reverse lookup on
each, and format the output neatly, like "IP=192.168.0.1,
... (0 Replies)
Hi All,
I have two files file1 and file2(lookup file).I need to map more than one keyfields of file1 with file2.how can we achieve it using awk.
file1(max 2.2 million records)
--------------------------
680720|680721|077
680720|680721|978
680721|680722|090
file2(no idea about the... (1 Reply)
I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)