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.
Boy, I sure hope this isn't your homework. You should be able to use ls piped to grep to do this, something like >ls -d |grep whattofind,
You could do it with something like this:
No this is no homework assignment.
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.
Thanks wolfperkins, I tried that with a smaller sample and it worked perfectly.
You might want to post a couple of lines from your csv file. For example, is it of the form
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".
|All times are GMT -5. The time now is 04:58 AM.|