lbbros Posted February 2, 2006 Report Share Posted February 2, 2006 (edited) Hello. I've stumbled across this problem, seeing if I can sort it out. I have two text files, that contain one term per line. The second file contains some terms that are common to the first one. I need to find a way to (using shell scripting, perl, or python): a. identify the common items; b. identify where the common items are in the first file (with line number). Point b is what I can't seem to do. I can easily get the common items with the bash join command but I haven't found a way to "trace" them back to their positions in the first file. I can't seem to get this issue sorted out. If you have any advice, I'd be very helpful. Edited February 3, 2006 by lbbros Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 3, 2006 Report Share Posted February 3, 2006 grep -n -f file2.txt file1.txt file1.txt test stuff more letters dogs cats frogs file2.txt nothing test hunger frogs something test hurricane < omar ~ > grep -n -f file2.txt file1.txt 1:test 7:frogs Quote Link to comment Share on other sites More sharing options...
lbbros Posted February 3, 2006 Author Report Share Posted February 3, 2006 Thank you very much! I didn't know about such use for grep. Quote Link to comment Share on other sites More sharing options...
neddie Posted February 3, 2006 Report Share Posted February 3, 2006 That is by far the coolest thing I've read all morning :D I'd seen the question but didn't have a clue how to solve it. Perfect answer, Steve! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.