Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

8
How to compare two lists of pathnames and isolate only unique filenames
Post Body

I'm trying to figure out a way to compare all the files of a certain type (let's call it .mp3 for sake of this example) on one drive with all the .mp3 files on another drive. Based solely on filenames I want to find files on DriveA that do not exist on DriveB. The file path does not matter at all.

 

So, if there is a file "foo/bar/file10.mp3" on DriveA and a file "zap/dap/map/file10.mp3" that file will be omitted from the results because "file10.mp3" exists on both drives.

 

So using the commands:

find DiveA -name "*mp3" > DriveA.txt
find DiveB -name "*mp3" > DriveB.txt

I can get a list of all the files and pathnames for DriveA and then for DriveB. But I can't figure out how then take those two lists and create a new list of pathnames for files that exist on DriveA but do not exist on DriveB.

I just want to use the filename to compare, not the pathname. I'm imagining there is some way to use diff to isolate the unique filenames but I'm not really sure – a little beyond my skillset.

Filenames/paths also can have spaces in them so piping the results through basename has been difficult for me, though even if I figured that out I'm not sure what I would do next!

Any help appreciated!

 

EDIT: /u/gumnos seems to have a winner with this use of the awk command:

$ awk -F/ 'FNR==NR{b[$NF]=$0; next} !($NF in b)' DriveB.txt DriveA.txt

Works for me on initial testing. I put one unique file out of a few hundred on my test folders and this picked it out.

Author
Account Strength
60%
Account Age
4 years
Verified Email
No
Verified Flair
No
Total Karma
1,813
Link Karma
81
Comment Karma
1,732
Profile updated: 1 week ago
Posts updated: 1 week ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago