Matching Between Two Files:
I have two files, a.txt and b.txt. The file a.txt (3 columns) is containing the data in file b.txt (1 column) and more. What I am looking to do is to search in a.txt for each element in b.txt, and print its corresponding line. Here is a partial cut of the two big files:
a.txt Code:
planetlab4-dsl.cs.cornell.edu 42.4436 -76.4816 Code:
planetlab2.cnis.nyit.edu Code:
planetlab2.cnis.nyit.edu 40.814 -73.6081 |
Here's one possible solution.
Hash the contents of file a, then look up the fields in file b. If there's a match, print it. Code:
#!/bin/bash |
Worked perfectly, thanks a lot.
All the best |
There is also the command join:
Code:
$ join <(sort a.txt) <(sort b.txt) |
Quote:
Quote:
|
All times are GMT -5. The time now is 11:23 PM. |