File content deletion

Hi Everyone,

There are certain files under a folder 'ABC' and the entries for these files are there in another file(fname) under a different folder 'XYZ'. I want to compare the folder contents(ABC) with
the file(fname) contents and delete the mismatching / non-existing ones from the file, fname.

thanks in advance

Something like this:

> ls -1
abc
bar
baz
def
foo
> cat ../files.txt
abc
def
bar
> ls | grep -vf ../files.txt | xargs rm
> ls -1
abc
bar
def

Hi pludi,

This deletes the files from the folder after comparison.

to be more specific about my problem, if

abc
bar
baz

are the files under 'ABC', the same entries(only entries) exist within files.txt under XYZ. In case, files.txt under XYZ has additional entries

def
foo

apart from abc, bar and baz, then after comparison, only the additional two entries:def and foo need to be removed from files.txt. The contents of 'ABC' should remain untouched.

Thank you

Am I being thick or is this the same effect as copying the list of files in directory ABC to the file "fname" ?

hi methyl,

the files under ABC get added to fname. entries from fname get deleted after the files get processed and files under ABC get renamed. So while fname gets emptied after a while, entries might pile up if a mismatch happens. this shouldn't occur. hence the reason for comparison and deletion

any suggestions welcome