Search code examples
phpcomm

Comm, awk alternative for php


I have 2 files:
images1.txt
--file1
--file2
--file5
--file6
--file7
images2.txt
--file1
--file5
--file6

I need to be created file images_to_delete.txt with expected result:
images_to_delete.txt
--file2
--file7

I know i could do this with bash using command:

awk 'NR==FNR{a[$0];next}!($0 in a)' images2.txt images1.txt > images_to_delete.txt

Is there any possibility to do this in PHP without using shell_exec?

Thank you.


Solution

  • By using these :

    read files into an array file function

    get difference between two arrays array_diff function