For something like this, a more powerful language such as python seems to do the trick...
Code:
#!/usr/bin/python
import os
from fnmatch import filter
def readInfile(infile):
f = open(infile, "r")
text = f.readlines()
f.close()
return text
def searchFile(files, file, text):
for page in files:
for line in text:
if page in line:
if not page in keep:
keep.append(page)
else:
if not page in delete:
delete.append(page)
keep, delete = [], []
php_pages = filter(os.listdir(os.getcwd()), '*.php*')
for php_page in php_pages:
searchFile(php_pages, php_page, readInfile(php_page))
print "Keep these:"
for file in keep:
print "\t %s" % file
print "Delete these:"
for file in delete:
if not file in keep:
# os.remove(file)
print "\t %s" % file
This seems to work well on my system with a few scratch files I created. If you are happy with the results then you can get the script to actually just delete the files for you...
Sorry, the script should actually work now