I have a file sortedfile.txt
with a list of file names. I am looking to search another file , ngfilelist.txt
containing a file list for all duplicates files in sortedfile.txt
.
I am using this command
for X in `uniq -d ~/Desktop/sortedfiles.txt`; do grep "$X" ~/Desktop/ngfilelist.txt; done
What should I correct in this?
I'd do something like this:
Instead of using a
for
loop, I find easier to usexargs
to run agrep
for every line insortedfiles.txt
againstngfilelist.txt
. The output is a list the file names found in both files.Note that
^
and$
are used to match only complete file names since probably partial matches aren't considered as valid results to your problem.