Hi,
I want to list only the file names which do not contain a specific keyword or search string.
OS: Solaris
Also is there any way ; through the same script I can save the output of search to a CSV (comma seperated) so that the file can be used for inventory purpose.
Any assistance will be highly appreciated.
regards
Sujoy
Use:
grep -vl <Pattern> <Files-List>
'-v' is for "Not Existing"
'-l' is for "Only Output The File-Name"
era
March 28, 2008, 12:29pm
3
That will print any file which contains a line which doesn't match the pattern. I imagine the task was to find files which do not contain the pattern anywhere.
Sorry! era is right!
You should then try this:
for f in <file-list>
do
grep <Pattern> $f >/dev/null || echo $f
done
And please be more specific on the second part of your problem.
(may be give examples of what you expect to be in the CSV file)
Hi,
Thank you very much for the solution. It worked.
For the 2nd part of my request;
suppose the above command produces output like:
/usr/data/config/apache/backup/www.under_configuration_16-141/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-143/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-161/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-166/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-174/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-175/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-178/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-179/vhost.conf
/usr/data/config/apache/backup/www.under_configuration_16-187/vhost.conf
I want to extract only the www site name (i.e only the URL).
era
March 31, 2008, 9:10am
6
If they are all in that directory tree at the same depth, simply
cut -d/ -f7
See man cut for the full scoop. If that doesn't work, I guess you will have to familiarize yourself with sed or awk.