How to search multiple directories for multiple files?
Ok, so am newbie obviously, have to make a script to have a user enter one or more filenames and one or more .tar filenames - I need for the user to be able to enter as many filenames and as many tar files as they want - I then need the script to display the filename and the matching .tar which contains it.
Stumped! Came across below, find . -name "*.tgz" -exec tar tzf {} \; > list.txt # copy all contents of all tar files to list??? But this only give the file names not versions or associated archive_filenames. Is it something like below of a complex AWK jobbie? Code:
#!/bin/bash |
If your purpose is to search for file, entered by user, to search in a tar file, then why don't you do like:
Code:
#!/bin/bash |
Quote:
So sample out put might be: Enter file name/s: bill bob sam frank jim Enter tar file name/s: accounts_dept.tar.gz sales_dept.tar.gz marketing_dept.tar.gz And the "find" resluts as something like: bill sam backed up in accounts_dept.tar.gz frank backed up in marketing_dept.tar jim not found bob not found ..... no idea where to start??!! |
Look, putting one tar file and than one file, which is to be searched in that tar, is a complicated plus inconvenient task.
So better use arrary here. Either insert all tar files in an arrary or insert all those files which are to be searched, in the arrary. Then use a simple for or while loop to search the same. Code:
tarfiles=(accounts_dept.tar.gz sales_dept.tar.gz marketing_dept.tar.gz ) |
Quote:
Great thanks |
All times are GMT -5. The time now is 02:33 PM. |