Need to find if a matching file exist from a list of possible file names
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need to find if a matching file exist from a list of possible file names
I am sure this questions has been asked before but I can not seem to find it here. I would appreciate if someone can help or point me to a thread that has already answered this.
I am guessing this can be done with a simple bash script, but I am not a scripter so help would be appreciated. I have a list of about 6500 folder names that I need to see if they still exist on the system. The folders will all be under the same parent directory. Currently I have the list in a csv file but the format can be changed. If matches are found I need the folder name outputted to a text file so I can manually check weather they are still being used.
If anyone can help me with this or point me in the right direction I would appreciate it.
This may be something that should be obvious-- but I don't know the answer and can not find it in the ls man page. How do I get it to search for folders that match the data in a csv file (or any other file)? In other words how do I input data from a file into ls to search for?
EDIT, I had already started to reply and got distracted before I submitted. When I submitted I noticed wolfperkins had another response. I will try that.
You might want to post a couple of lines from your csv file. For example, is it of the form
"item1","item2","item3"
or
item1,item2,item3
or
item1,"item with comma, in name",item3.
You can get a list of the directories under the parent directory using the find command:
find /path/to/parent/directory -type f
Given the large number of entries, it may work best if you can process the csv file and produce a file of directories. (Let's call it csvdirs for illustration sake.)
Then you could use:
grep -f csv-dirs current-dir-list
to find matches. A better way would be to sort both lists and use the "comm" command.
comm compares to sorted lists and outputs three columns.
First column: lines unique to file1; Second column: lines unique to file2; Third column: lines common to both files. You can turn off any of the columns with the -1, -2, and -3 options.
To list common entries, use "comm -12 file1 file2".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.