I have this 2 files:
file1
Ruby
C
Visual Basic
R
Objective-C
Basic
HTML
file2
5. ab cde fg Java hij kl
2. ab PHP dddf llf
4. cde fg z o Objective-C oode
8. a12b cde JavaScript kdk
6. ab99r cde Visual Basic llso dkd
1. lkd dsk Ruby kksdk
3. Python dsdls
7. kdjd C jdjd
9. CSS dkdsk
7. kkd Basic jjs
3. rooor R kdk
I´d like to search the strings in file1 and if they are found within file2, then print the "the string of file1", followed by line number in file2, and the line of file2 where each string is present.
The output format would be like this:
find "string" of file1|Line in file2 where "string" of file1 was found| text of line in file2 where "string" of file1 was found
For the sample file1 and file2 the output I´m looking for is:
Ruby|6|1. lkd dsk Ruby kksdk
C|8|7. kdjd C jdjd
Visual Basic|5|6. ab99r cde Visual Basic llso dkd
R|11|3. rooor R kdk
Objective-C|3|4. cde fg z o Objective-C oode
Basic|10|7. kkd Basic jjs
HTML|Not found
I've tried with the following code, but doesn´t find anything. My real file1 has about 32K lines and real file2 has about 48K lines.
require 'set'
f2_set = File.readlines("file2.txt").map(&:chomp).to_set
File.foreach("file1.txt") { |line| puts line if f2_set.include?(line) }
Thanks for any help
UPDATE
Below I show file1 and file2 proposed by @CarySwoveland and how would be the output for those inputs.
UPDATE2
