compare two files using Awk!!
I have to files. In the first file I have a unique emp.id as first field and in the second file I have the same emp.id as second field. I want join (or match) these two files on the basis of emp.id (i.e., first file with second file.) and print the matched lines with all the fields of both the files.
Thank you in advance.
Show some examples of what you want.
Please be more clear about the questions you ask. Many of your questions seem rather lazy, with minimal though or effort. You'll get more if you spend more time formulating "intelligent" questions.
This sounds like the source of these files are tables from a relational database such as mysql. The emp.id field in the first file sounds like emp is the employee table, with "id" being the primary key; and in the second file, emp.id is a foreign key.
If that is the case, why not use a database client (such as the mysql command) and enter the sql SELECT command to return the information from the database containing the information you want. To paraphrase the evil Russian General from the movie Golden Eye, "Use the database! That's what it's for."
Generally a lot depends on the particular of your two files. Is there a one-to-one relationship between the emp.id's in the two file? Is every id in one file present in the other and vice versa? If so, then you could sort each file and input the results to the paste command.
At least browse through the commands & the brief topics in the index page by entering "info coreutils".
To do what you want to do in a single awk script, you may need to use "readline" to read from table2 while processing a line from table1.
If the same one-to-one conditions exist, then you can use paste to assemble a long line from each table. Then in awk, you can check that the two fields containing the id match up and if they do, print out the fields you want.
emp.id name quantity amount
11111 xyx 25 5500
22222 sss 55 7500
33333 wes 120 8898
add1 add2 add3 empid pin
rd1 blah blah 11111 2324
rd2 blah blah 22222 5565
rd4 blah blah 33333 6548
I want to match above files on emp.id fields using awk.
Thank you all.
|All times are GMT -5. The time now is 06:53 PM.|