grep list of directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep list of directories
# 1  
Old 10-19-2011
grep list of directories

Hi all,

it possible creating a file with list of directories, and using grep to find pattern on only directories and subdirectories contained in that file?
And it is done?

regards
# 2  
Old 10-19-2011
Yes it is. As a start try the find command to generate your list. You can either redirect output to a file and use grep on it or just use a pipe and hand it over to grep to search your pattern.
# 3  
Old 10-19-2011
Can you give me an example of how it is done with grep?

imagine that i have
dir
- subdir1
- subdir2
- subdir3
- subdir4
- subdir5

and my list contains subdir2 and subdir 4.

how can use this list with grep?

actually i'm using this
Code:
grep -rwn --exclude=\*.svn\* pattern ./ to search

the problem this will search in all subdir. if i have 100 subdir and i only want results from 30subdirs
after utilize this command will return a lot of info, as you can see also will return lot info that i don't care.

regards

Moderator's Comments:
Mod Comment Use code tags, you got a PM.

Last edited by zaxxon; 10-19-2011 at 02:06 PM.. Reason: code tags
# 4  
Old 10-19-2011
I am not sure if I understood what you want to achieve. Anyway here is an example.
Given your list A.txt that contains the search patterns:
Code:
subdir2
subdir4

and some directory structure on disk like:
Code:
subdir1
subdir2
subdir3
subdir4
subdir5
subdir6
...

and lot's of stuff you don't want, you could try like:
Code:
find /entry/dir -type d -name "subdir*" | grep -f A.txt

# 5  
Old 10-19-2011
that command doesn't work for what i want.
let me see if i can explain better (english is not my native language).
i have one directory, with multiples sub-directories, each sub-directories has multiples files.
what i want is searching of certain pattern in files contained in some sub-directories, not all sub-directories, in other words, the names of this certain directories will be in list.txt.

something like this, search "qwerty" in all files in directories in the list.txt
i hope i have explained better.

regards

Last edited by bspirit; 10-20-2011 at 06:32 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

List the directories, having given pattern in the directories name, sorted by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, having given pattern in the directories name, sorted by creation date. Example: Directories with name "pkg32*" or "pkg33*" 2. On the output of 1. list the directories by creation date as sort order, with creation date... (2 Replies)
Discussion started by: Siva SQL
2 Replies

2. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

3. UNIX for Dummies Questions & Answers

Using grep command to find the pattern of text in all directories and sub-directories.

Hi all, Using grep command, i want to find the pattern of text in all directories and sub-directories. e.g: if i want to search for a pattern named "parmeter", i used the command grep -i "param" ../* is this correct? (1 Reply)
Discussion started by: vinothrajan55
1 Replies

4. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

5. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

6. UNIX for Dummies Questions & Answers

How to Grep list of directories

I have multiple systems with each having its own log directory containing log file pertinent to that system. I have constructed a find/grep statement to get the list of directories ending in log, but I can't seem to pipe that to grep (via xargs) to have grep search each file in the log directories... (8 Replies)
Discussion started by: jmgibby
8 Replies

7. Shell Programming and Scripting

List of directories into a nested list

I have a list of directories like this a a/b a/c a/d a/d/e a/d/f a/d/g a/d/g/h a/i I would like to convert this list into another list, nested like this a{b{} c{} d{e{} f{} g{h{}}} i{}} Here is a pseudo algorithm for this Add a: (1 Reply)
Discussion started by: Ilja
1 Replies

8. Shell Programming and Scripting

how to grep some text in a directory and as well as in its sub-directories

Hi Friends Little help is required. I want to grep some string in a directory as well as in its sub-directoies. Thanks Joy:confused: (4 Replies)
Discussion started by: itsjoy2u
4 Replies

9. UNIX for Dummies Questions & Answers

how to list directories only

I would like to know how to list directories only without a / at the end. I would like to only see them in my current dir. for example ls - d */ gives dir1/ dir2/ dir3/ dir4/ but is there a way to get only dir1 dir2 dir3 i need it to use them as inputs in a foreach loop... (3 Replies)
Discussion started by: yodadbl07
3 Replies

10. UNIX for Dummies Questions & Answers

grep recursive directories

I am trying to locate a file or files with specific data in them. Problem is the file(s) could reside in any one of many directories. My question is. Is there a way of recursively greping directories for the file(s) with the data I am looking for. I have tried - 1. $HOME> grep 47518 | ls... (8 Replies)
Discussion started by: jagannatha
8 Replies
Login or Register to Ask a Question