locating a string pattern in a tree


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting locating a string pattern in a tree
# 1  
Old 05-24-2007
locating a string pattern in a tree

Hi,

How can i find a specific string pattern in the entire tree(several directories containing multiple sub directories ) ?
$ find ./ -type f |grep "<pattern>" will not do as it will just give the names of directories (relative pathname containing the pattern).

grepping for the pattern in a directory containing files only work,but this is not what i want.
i need to look for the specific <pattern> in the entire tree .

"xargs" might do the job,but i've never used it before : (

Thanks,
~amit
# 2  
Old 05-24-2007
i guess i found what i was looking for Smilie
find ./ -type f|xargs grep <pattern>|more
# 3  
Old 05-24-2007
Code:
find . -type f -exec grep "<pattern>" {} \;

Code:
find . -type f | xargs grep "<pattern>"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Locating all the scripts which start with:#!

Hi, I need to find all the executable shell scripts under /home dirctory and its sub directories. I would like to print the path to the files , which include in the header of the file: #! (Actually its the first line of the file). I have tried : find . -name "*" -type f -exec sh -c ' ... (14 Replies)
Discussion started by: Yoav
14 Replies

2. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

3. Solaris

Locating files!

My question is : -How do I locate files of specific user in specific folder. In other words, How do I find files that belong only to "root" user, in /etc folder? (5 Replies)
Discussion started by: alexex666
5 Replies

4. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. UNIX for Dummies Questions & Answers

Locating a hidden file

it seems one of my server's account was compromised. I caught a perl script running a hack/attack script: 20:23 /usr/bin/perl ./up **.**.**.** 0 120 I've disabled the user etc, but I cannot find the script "up" anywhere in the server. I tried using locate or find. any ideas? (1 Reply)
Discussion started by: MaRiOsGR
1 Replies

7. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

8. Shell Programming and Scripting

extract a string within a string using a pattern

hi all, i have a file name using the following pattern: PREFIX: AR SOURCE: LEGACY DATETIME: YYYYMMDD_HH24MISS SUFFIX: .txt sample filename: AR_LEGACY_20101104_105500.txt i want to extract the source which is LEGACY in this case. how do i do this using shell? thanks. (4 Replies)
Discussion started by: adshocker
4 Replies

9. Shell Programming and Scripting

Dynamically locating a file

Hi, I have a requriement where in I need to install a s/w by executing the installable file through a script. The script currently contains the path of the installable file. I need to now update the script accordingly such tht it identifies the location of the installable file automatically and... (1 Reply)
Discussion started by: yoursdavinder
1 Replies

10. UNIX for Dummies Questions & Answers

Locating C source code

Hi, I'm trying to locate where on the filesystem I can find the source code for C standard libraries. The reason why is I'd like to look at the implementation of "'atoi"'. I've tried a brutal search of "grep -r "atoi" *" from root as root but the search took too long. I'm running redhat 7.3... (3 Replies)
Discussion started by: chadwick0
3 Replies
Login or Register to Ask a Question