Sponsored Content
Top Forums Shell Programming and Scripting How to recursively search for a list of keywords in a given directory? Post 302640827 by alister on Tuesday 15th of May 2012 10:48:41 AM
Old 05-15-2012
Whenever you need to traverse the a filesystem but the command does not support -R/r, think find(1).
Code:
find target/dir -type f -exec grep -iFf procnamelist /dev/null {} \;

If your find is compliant with the POSIX 2004 edition or later, use + to increase efficiency:
Code:
find target/dir -type f -exec grep -iFf procnamelist /dev/null {} +



Quote:
Originally Posted by glev2005
Code:
cat procnamelist|while read line;do fgrep -Rif $line target/dir/*;done

That would have failed even if -[r|R] were supported. A line from procnamelist, which is a pattern to match, is treated as a filename argument to -f. If you put procnamelist where it belongs, after -f, the pipe and while loop serve no purpose.


Quote:
Originally Posted by pamu
Code:
while true
do
while read line
do
cat file | grep "$line" 
done<procnamelist
done

The sole reason for the existence of this thread is file system traversal. This proposal is an infinite loop that reads one file over and over and over and ...

Regards,
Alister

Last edited by alister; 05-15-2012 at 11:56 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and replace words between two keywords

Hi, I have a file which contains the following : select * from test where test_id=1; select id from test1, test2 where test_id=1 and test_id=2; select * from test1, test2, test3 where test_id=4 and test2_id where in (select test2_id from test2); select id1, id2 from test ... (6 Replies)
Discussion started by: vrrajeeb
6 Replies

2. Shell Programming and Scripting

How to search for keywords in subsequent lines

Hi all, I am looking for a coomand to search for the keywords in susequenct lines. Keyword1 in a line and Keyword2 in the very next line. Once i found the combination ineed to print the lines with patterns and the line above and one below. I am giving an example here: Keywords are :ERROR and... (12 Replies)
Discussion started by: rdhanek
12 Replies

3. UNIX for Dummies Questions & Answers

Linux shortcutkey to search specific file from a list of directory?!

Hi, I'm the new user of linux/unix. Can I ask that anybody know how to use the linux/unix shortcut key to search a specific file from a list of directory? For example, I know the file name that I want to search. But I forget which directory or location is my desired file put.Got any shortcut... (7 Replies)
Discussion started by: patrick87
7 Replies

4. Shell Programming and Scripting

Search a file with keywords

Hi All I have a file of format asdf asf first sec endi asdk rt 123 ferf dfg ijglkp (7 Replies)
Discussion started by: mailabdulbari
7 Replies

5. UNIX for Advanced & Expert Users

Need to search for keywords within files modified at a certain time

I have a huge list of files in an Unix directory (around 10000 files). I need to be able to search for a certain keyword only within files that are modified between certain date and time, say for e.g 2012-08-20 12:30 to 2012-08-20 12:40 Can someone let me know what would be the fastest way... (10 Replies)
Discussion started by: virtual123
10 Replies

6. Shell Programming and Scripting

search between keywords and make a single line

have a very big file where need to format it like below example file: abcd today is great day; search keyword 'abcd' and append to it all words till we reach ; to make it a single line. output should look like. abcd today is great day; There are many occurrence of such... (2 Replies)
Discussion started by: giri4332
2 Replies

7. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

8. Shell Programming and Scripting

Search files in directory for keywords using bash

I have ~100 text files in a directory that I am trying to parse and output to a new file. I am looking for the words chr,start,stop,ref,alt in each of the files. Those fields should appear somewhere in those files. The first two fields of each new set of rows is also printed. Since this is on a... (7 Replies)
Discussion started by: cmccabe
7 Replies

9. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies
MAN.CONF(5)						      BSD File Formats Manual						       MAN.CONF(5)

NAME
man.conf -- configuration file for manual pages DESCRIPTION
The man.conf file contains the default configuration used by man(1), apropos(1), whatis(1), catman(8), and makewhatis(8) to find manual pages and information about manual pages (e.g. the whatis database). Manual pages are located by searching an ordered set of directories called the ``man path'' for a file that matches the name of the requested page. Each directory in the search path usually has a set of subdirectories in it (though this is not required). When subdirectories are used, there are normally two subdirectories for each section of the manual. One subdirectory contains formatted copies of that section's manual pages that can be directly displayed to a terminal, while the other section subdirectory contains unformatted copies of the pages (see nroff(1) and mdoc(7)). Formatted manual pages are normally named with a trailing ``.0'' suffix. The man.conf file contains comment and configuration lines. Comment lines start with the ``#'' character. Blank lines are also treated as comment lines. Configuration lines consist of a configuration keyword followed by a configuration string. There are two types of configura- tion keywords: control keywords and section keywords. Control keywords must start with the ``_'' character. The following control keywords are currently defined: _build identifies the set of suffixes used for manual pages that must be formatted for display and the command that should be used to for- mat them. Manual file names, regardless of their format, are expected to end in a ``.*'' pattern, i.e. a ``.'' followed by some suffix. The first field of a _build line contains a man page suffix specification. The suffix specification may contain the nor- mal shell globbing characters (NOT including curly braces (``{}'')). The rest of the _build line is a shell command line whose standard output is a formatted manual page that can be directly displayed to the user. There should be exactly one occurrence of the string ``%s'' in the shell command line, and it will be replaced by the name of the file which is being formatted. _crunch used by catman(8) to determine how to crunch formatted pages which originally were compressed man pages: The first field lists a suffix which indicates what kind of compression were used to compress the man page. The rest of the line must be a shell command line, used to compress the formatted pages. There should be exactly one occurrence of the string ``%s'' in the shell command line, and it will be replaced by the name of the output file. _default contains the system-wide default man path used to search for man pages. _subdir contains the list (in search order) of section subdirectories which will be searched in any man path directory named with a trail- ing slash (``/'') character. This list is also used, even if there is no trailing slash character, when a path is specified to the man(1) utility by the user, by the MANPATH environment variable, or by the -M and -m options. _suffix identifies the set of suffixes used for formatted man pages (the ``.0'' suffix is normally used here). Formatted man pages can be directly displayed to the user. Each suffix may contain the normal shell globbing characters (NOT including curly braces (``{}'')). _version contains the version of the configuration file. _whatdb defines the full pathname (not just a directory path) for a database to be used by the apropos(1) and whatis(1) commands. The pathname may contain the normal shell globbing characters, including curly braces (``{}''); to escape a shell globbing character, precede it with a backslash (``''). Section configuration lines in man.conf consist of a section keyword naming the section and a configuration string that defines the directory or subdirectory path that the section's manual pages are located in. The path may contain the normal shell globbing characters, including curly braces (``{}''); to escape a shell globbing character, precede it with a backslash (``''). Section keywords must not start with the ``_'' character. A section path may contain either a list of absolute directories or a list of or relative directories (but not both). Relative directory paths are treated as a list of subdirectories that are appended to the current man path directory being searched. Section configuration lines with absolute directory paths (starting with ``/'') completely replace the current man search path directory with their content. Section configuration lines with absolute directory paths ending with a trailing slash character are expected to contain subdirectories of manual pages, (see the keyword ``_subdir'' above). The ``_subdir'' subdirectory list is not applied to absolute section directories if there is no trailing slash. In addition to the above rules, the man(1) command also always checks in each directory that it searches for a subdirectory with the same name as the current machine type. If the machine-specific directory is found, it is also searched. This allows the manual to contain machine-specific man pages. Note that the machine subdirectory does not need to be specified in the man.conf file. Multiple specifications for all types of man.conf configuration lines are cumulative and the entries are used in the order listed in the file; multiple entries may be listed per line, as well. FILES
/etc/man.conf Standard manual configuration file. EXAMPLES
Given the following man.conf file: _version BSD.2 _subdir cat[123] _suffix .0 _build .[1-9] nroff -man %s _build .tbl tbl %s | nroff -man _default /usr/share/man/ sect3 /usr/share/man/{old/,}cat3 By default, the command ``man mktemp'' will search for ``mktemp.<any_digit>'' and ``mktemp.tbl'' in the directories ``/usr/share/man/cat1'', ``/usr/share/man/cat2'', and ``/usr/share/man/cat3''. If on a machine of type ``vax'', the subdirectory ``vax'' in each directory would be searched as well, before the directory was searched. If ``mktemp.tbl'' was found first, the command ``tbl <manual page> | nroff -man'' would be run to build a man page for display to the user. The command ``man sect3 mktemp'' would search the directories ``/usr/share/man/old/cat3'' and ``/usr/share/man/cat3'', in that order, for the mktemp manual page. If a subdirectory with the same name as the current machine type existed in any of them, it would be searched as well, before each of them were searched. SEE ALSO
apropos(1), machine(1), man(1), whatis(1), whereis(1), fnmatch(3), glob(3), catman(8), makewhatis(8) BSD
December 27, 2011 BSD
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy