Merging two file based on comparison of first columns
Respected Members.
Hello.
This is my first post in the forum. I will try to follow all the rules as prescribed by the forum. In case of non-compliance, I request you to kindly give me some more time to understand and abide by them.
I am working on two files. I wish to merge the two files and based on the merged file want to do some calculations like addition/subtraction of the columns.
My first file is
The second file is:
The file is merged by comparing first column of both files. If the number in first column in first file is same as in second file then column two of second file must be appended as column three in first file. In case of those lines in first file which are not present in second file, then also that line must come in the merged file but with 000000 as the number appended in third column for that line. Similarly for the lines in second file that does not have the same number in first column of first file, then also that line must come in merged file but with 000000 as the number in second column and value of that line in third column. That is, all the lines of both files must come in merged file with either 000000 in third column or 000000 in second column. Then I have to subtract the second and third columns in merged file.
Tilll now , I have done the following
As seen, the merged file is not containing lines which are in file 2 only. Also I want to write 000000 in third column of merged file for the lines not in file 2, i.e., first and sixth line must contain 000000 in third column. For the lines which are unique in file 2 must contain 000000 in second column in merged file.
My code for this is as below:
I have taken help from other posts in the forum also for which I am thankful to the concerned members.
Kindly help me.
Manoj
Last edited by manojmalhotra; 10-16-2014 at 04:26 AM..
hi
i need to select a few columns of two txt files and write it to a new file. there is one common field for both of these files.
plz help me in this
thanks in advance (4 Replies)
Hi,
I want to select columns from multiple files and combine them in one file. The files are simulation-data-files with 23 columns each and about 50 rows. I now use:
cut -f 11 Sweep?wing-30?scale=0.?0?fan2?.txt | pr -3 | awk '{printf("\n%s\t%s\t%s",$1,$2,$3)}' > ../Data_Processed/output.txtI... (1 Reply)
Hi Guys. I have tried the commands sort and join. But I couldn't able to to find the command for joining in a single line based on keys.My example inputs and outputs are like the following.
Help would be appreciated.:D
Input file
a1tabXXXXXXX
a2tabXXXXXXX
a6tabYYYYYYYYY
a71tabXXXXXXX... (7 Replies)
Okay, first of all, thanks to everyone who's helped me out before... I appreciate the opportunity to learn.
I have two iTunes XML files, and I simply want to compare the contents, then merge. Theoretically, this will allow me to merge two libraries, keeping playlists intact (depending on iTunes'... (4 Replies)
Hi there,
I'm trying to merge two files and make a third file.
However, two of the columns need to match exactly in both files AND I want everything from both files in the output if the two columns match in that row.
First file looks like this:
chr1 10001980 T A
Second... (12 Replies)
Hi
I have 2 files
1.del
----
1,2,3,4,5
1,2,3,4,4
1,1,1,1,2
2.del
----
1,2,3,4,5
1,
1,2,3,4,4
1,1,1,1,2
I need to compare the above two files in unix, as in the output should only tell the difference in contents as I should get only the line
1 ( from 2.del) , rest all lines are... (4 Replies)
Hi,
I have following input in the file in which i want to club the entries based on $1. Also $11 is equal to $13 of other record(where $13 must be on higher side for any $1) then sum all other fields except $11 & $13. Final output required is as follows:
INPUTFILE:
... (11 Replies)
Respected Members.
Hello.
This is my first post in the forum. I will try to follow all the rules as prescribed by the forum. In case of non-compliance, I request you to kindly give me some more time to understand and abide by them.
I am working on two files. I wish to merge the two files... (1 Reply)
Hi,
I am facing issues while accomplishing below task.
We have two files Test1.txt and Test2.txt. We have to match 1st column of Test1.txt file with 2nd column of Test2.txt and then merge 2nd file with the 1st file. In the output we should select column 1 and 2 from the 1st file and column 1... (5 Replies)