Trying to combine the matching $5 values between file1 and file2. If a match is found then the last $6 value in the match and the sum of $7 are outputted to a new file. The awk below I hope is a good start. Thank you .
file1
file2
awk tried with error
desired output
Last edited by cmccabe; 05-21-2016 at 02:02 PM..
Reason: fixed format
Could you please try following and let me know if this helps.
1st: If you need to have exact count like file2 of 2nd last field(where I am assuming like it could be anything/any number, though your Input_file shows only in increment order or each occurrence of the field 4th). So always it will print the latest value of the 4th field's 2nd last field here, without taking care what it is.
Output will be as follows.
2nd: In case your 2nd last field shows the number of occurrences of 4th field, then following could help you.
Output will be as follows.
Now coming on to the confusion which I have by reading your post, if you see carefully you have shown Output_file's last field(which is SUM of the last fields), first line it shows 250 so it looks you are taking sum from file1 BUT on same time second line shows 385 which shows SUM should be from file2. So above solutions are taking SUM of values in file2 not in file1. Please try above ones and let me know how it goes then.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
The first awk is always the case. The only thing that may change is the output (depending on the case). How can I print only $5, $6, $7 ? Thank you for your help, iworks great .
The first awk is always the case. The only thing that may change is the output (depending on the case). How can I print only $5, $6, $7 ? Thank you for your help, iworks great .
Hello cmccabe,
A little change in my previous code, could you please try following and let me know if this helps.
Output will be as follows.
Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Hi, I have two TEST files t.xyz and a.xyz which have three columns each. a.xyz have more rows than t.xyz. I will like to output rows at which $1 and $2 of t.xyz match $1 and $2 of a.xyz. Total number of output rows should be equal to that of t.xyz.
It works fine, but when I apply it to large... (6 Replies)
Trying to use awk to store the value of $5 in file1 in array x. That array x is then used to search $4 of file1 to find aa match (I use x to skip the header in file1). Since $4 can have multiple strings in it seperated by a , (comma), I split them and iterate througn each split looking for a match.... (2 Replies)
I've written an awk script to compare two fields in two different files and then print portions of each file on the same line when matched. It works reasonably well, but every now and again, I notice some errors and cannot seem to figure out what the issue may be and am turning to you for help.
... (2 Replies)
In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
In the below awk I am trying output to one file those lines that match between $2,$3,$4 of file1 and file2 with the count in (). I am also trying to output those lines that are missing between $2,$3,$4 of file1 and file2 with the count of in () each. Both input files are tab-delimited, but the... (7 Replies)
Trying to combine strings that are a partial match to another in $1 (usually below it). If a match is found than the $2 value is added to the $2 value of the match and the $3 value is added to the $3 value of the match. I am not sure how to do this and need some expert help. Thank you :).
file
... (2 Replies)
Trying to use awk to find a keyword and return the matches in the row, but also $1 and $2, which are the unique id's, but they only appear once. Thank you :).
file
name 31 Index Chromosomal Position Gene Inheritance
122 2106725 TSC2 AD
124 2115481 TSC2 AD
121 2105400 TSC2 AD... (6 Replies)
Hi All,
I need to get the count of records in the file, if the passing parameter matches with the list of records in the file. Below is my example
source file: Test1.dat
20120913
20120913
20120912
20120912
20120912
20120912
20120912
20120913
20120913
20120912
In my script I am... (5 Replies)
Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file.
For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt
I tried with grep -A but it's not supported on my system.
I tried with awk,... (4 Replies)
I am trying to break a string into separate fields and print the field that matches a pattern. I am using awk at the moment and have gotten this far:
awk '{for(i=1;i<=NF;++i)print "\t" $i}' longstring
This breaks the string into fields and prints each field on a separate line.
I want to add... (2 Replies)