[TriLUG] Search for Duplicate Filename, Ignore Extension

Brian Blater brb.lists at gmail.com
Wed Nov 2 14:25:16 EDT 2011


On Wed, Nov 2, 2011 at 1:29 PM, Robert Dale <robdale at gmail.com> wrote:
> Generate database of files:
>
> find /some/path -type f | while read file; do echo `basename "${file%.*}"`\#${file}; done > /another/path/files.txt

This part works and generates the /another/path/files.txt

>
> Find dupes:
>
> cat /another/path/files.txt | cut -f 1 -d '#' | sort | uniq -c | grep -v "^.*1" |
> awk '{print $2}' | while read dupe; do grep -i ${dupe}\# /another/path/files.txt;
> done

This part I believe works as designed above, but it list all files in
the "files.txt" file. How can I get it to only list the files that are
duplicate?

Here is a test:

file1#/home/bbl/temp/file1.txt
file1#/home/bbl/temp/file1.text
file2#/home/bbl/temp/file2
file3#/home/bbl/temp/file3
file4#/home/bbl/temp/file4.doc

How would I get it to just show:

file1#/home/bbl/temp/file1.txt
file1#/home/bbl/temp/file1.text

Thanks for everyone's help. I definitely learn new things every time I
ask a question here.

Brian



More information about the TriLUG mailing list