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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep some text in a directory and as well as in its sub-directories
# 1  
Old 04-29-2008
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
JoySmilie
# 2  
Old 04-29-2008
not 100% sure what you mean... can you give an example?
# 3  
Old 04-29-2008
Reply

A -is directory B, C,D are the subdirectories. Under B G,H are the subdirectories. Each directory contains some files. I want to grep one string which can be there in any files. I don't want to go to each directory and then grep. I want to grep it from A directory itself.

Thanks
Joy
# 4  
Old 04-29-2008
try find ... (on HP-UX)

find /start_dir -type f -xdev -print -exec grep string {} \;

Will display the filename that contains searched and each occurance of the string if found.

Hope that helps ...
# 5  
Old 04-29-2008
Hi,
You can do this.

grep <your string> /path/to/the/dir/*

This lists all the matching cases of your string in that particular directory of your choice
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. UNIX for Dummies Questions & Answers

using grep command to find the pattern of text in all directories.

Hi all, i want to know the usage of grep command to find the pattern of text in all the directory and subdirectory. (1 Reply)
Discussion started by: vinothrajan55
1 Replies

4. Homework & Coursework Questions

Creating directories within a directory?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Ok i need to create a directory within another directory in one command. I'm already in a directory to. I need to... (6 Replies)
Discussion started by: gangsta
6 Replies

5. 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

6. Shell Programming and Scripting

going through files in a directory, and it's sub-directories

i have a c-shell script. and i pass it one or two arguments the first argument is the directory the second is the "-r" now, if i pass it only one, it searches the files ending in txt in that directory if i pass it two parameters, like "temp" and "-r" i want it to go through all the files and... (1 Reply)
Discussion started by: pantelis
1 Replies

7. Solaris

How list all directories in a directory?

Hi How can i list all the directories inside a directory? not only the directories in the present dir. also the directories inside directories present in the dirrectory. recursive. "find . -type d" will work with other Unix flavors but not with SunOS. Please help Robin (1 Reply)
Discussion started by: robinbannis
1 Replies

8. Shell Programming and Scripting

Scan directory and sub directories

I am really stuck on a issue and have not been able to find a solution. With the code below I need to not only scan the current directory which as you can see below is... /lcl/sit/apps/Tivoli/ But I also want it to scan all sub directories it finds under Tivoli as well for the same thing... (2 Replies)
Discussion started by: LRoberts
2 Replies

9. Shell Programming and Scripting

how many directories and files are there in a directory

I want to know how many directories and files are there in a directory and if the sub directory have any files i also need that also . I have done this far .... (4 Replies)
Discussion started by: smongam
4 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