Text File 1:
426684146543xxxx|xx|xxxx|xxx
407166210197xxxx|xx|xxxx|xxx
521307101305xxxx|xx|xxxx|xxx
521307101485xxxx|xx|xxxx|xxx
Text File 2:
521307
407166
If the lines in the 2nd text file exist in the 1st text file, I want it to show me all the matching lines from the 1st file
OUTPUT:
521307101485xxxx
521307101305xxxx
407166210197xxxx
My Answer:
php
$file1 = file('file1.txt', FILE_IGNORE_NEW_LINES);
$file2 = file('file2.txt', FILE_IGNORE_NEW_LINES);
$matches = array_intersect($file1, $file2);
foreach ($matches as $match) {
echo $match . "\n";
}
?>
Rate this post
5 of 5 based on 5527 votesComments