File 1: 1356775 lines
File 2: 9516 lines
File 2 contains lines of numbers which when matched in File 1 should be deleted from that file. Example:
File 1
34234323432 some useless stuff
23423432342 more useless stuff
98989898329 foo bar blah
65367389473 one two three
File 2
234234323
653673894
New File
34234323432 some useless stuff
98989898329 foo bar blah
My approach right now is to
- Read entire file2 content into an array
- Get first line of File1 and extract first 8 numbers
- Loop through entire array from step 1 to see if 8 numbers from step1 match
- If numbers don't match then write line from step1 into a new file
- If they match then break out of the loop and don't write the line to new file
- continue until there are no more lines to read from step2
However, since the file is so big, it take an enormous amount of time to do this since for each line in file1 we are looping through entire array(9516 elements). Is there a simpler way to do this type of file manipulation without putting records from file in a DB table.