Complex match of numbers between 2 files awk script
Hello to all,
I hope some awk guru could help me.
I have 2 input files:
File1: Is the complete database
File2: Contains some numbers which I want to compare
File1:
File2:
I would like:
- to know if the numbers in column1 of file2 are present in column5 of file1 and
get the value in column4 of file1 and compare it with value in column3 of file2
- If the number in file2 is present in file1, print the number, the value that has in file1 and value that has in file2
- If values are equal print "Yes, both values equal"
- If values are different print "Yes, both values different"
- If number in file2 is not found in file1 print number, value in file2 and "NOT_FOUND_in_File1"
Desired ouput:
PD: The real file1 has 5 million of lines and real file2 has hundred or some thousand of lines.
Thanks in advance for your help.
Last edited by Ophiuchus; 10-12-2012 at 02:13 AM..
@pamu: This approach of loading the entire file in memory might cause some performance issue in this scenario because the OP states that file1 has 5 million records.
For the join command to work, the file has to be sorted based on the key on which you are trying to join. Since the key to join is 5th field of file1, it is -k5. t is for delimiter. For more on the join command options, refer to the example 4 here.
Guru.
This User Gave Thanks to guruprasadpr For This Post:
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)
Basically, I have two files
dupestest.txt
152,153
192,193,194
215,216
290,291
2279,2280 2282,2283haftest.txt
152,ABBOTS ROAD
153,ABBOTS ROAD
154,ABBOTS ROAD
155,ABBOTS ROAD
156,ABBOTS ROAD
157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Hi Experts,
I am finding difficulty to get exact match:
file
OPERATING_SYSTEM=HP-UX
LOOPBACK_ADDRESS=127.0.0.1
INTERFACE_NAME="lan3"
IP_ADDRESS="10.53.52.241"
SUBNET_MASK="255.255.255.192"
BROADCAST_ADDRESS=""
INTERFACE_STATE=""
DHCP_ENABLE=0
INTERFACE_NAME="lan3:1"... (6 Replies)
Hello to all in forum,
Maybe an awk expert could help me with this complex task for me.
I have the input shown below and I would like to get the output as follow:
- I would like the output separated by commas.
- The header is fixed and will be the same always.
- For the lines containing... (22 Replies)
picked this up from another thread.
echo 1st_file.csv; nawk -F, 'NR==FNR{a++;next} a{b++}
END{for(i in b){if(b-1&&a!=b){print i";\t\t"b}else{print "NEW:"i";\t\t"b} } }' OFS=, 1st_file.csv *.csv | sort -r
i need to use the above but with a slight modification..
1.compare against 3 month... (25 Replies)
for every specific $1,$2 check the values ($2,$3) of their E ot I of input1 and overlap with input2.
Specify names based on output.
#######
if middle value is missing name them "SE"
if first value is missing name them "AFE"
if last value is missing name them "ALE"
if 2 middle values are... (1 Reply)
I am looking for a better way to match real numbers within a specified tolerance range. My current code is as follows:
if ($1 !~ /^CASE/) for(i=1;i in G;i++) if (G >= $5-1 && G <= $5+1)
{ print $1,$4,$5,J,G }
else { print $1,"NO MATCH" }
where $5 and G are... (3 Replies)
1. if the 1st row IDs of input1 (ID1/ID2.....) is equal to any IDNames of input2
print all relevant values together as defined in the output.
2. A bit tricky part is IDno in the output. All we need to do is numbering same kind of
letters as 1 (aa of ID1) and different letters as 2 (ab... (4 Replies)
if the column1 and 2 in both files has same key (for example "a" and "a1") compare each first key value(a1 of a) of input2 (for example 1-4 or 65-69 not 70-100 or 44-40 etc) with all the values in input1.
if the range of first key value in input2 is outof range in input1 values named it as out... (54 Replies)
i would like to enter (user input) a bunch of numbers seperated by space:
10 15 20 25
and use awk to print out any lines in a file that have matching numbers
so output is:
22 44 66 55 (10) 77 (20)
(numbers 10 and 20 matched for example)
is this possible in awk . im using gawk for... (5 Replies)