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.
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.
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/commandline...