Finding patterns through out all subdir


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding patterns through out all subdir
# 1  
Old 05-17-2004
Finding patterns through out all subdir

Hi all experts,
here is a problem which i would appreciate ur expertise.

I need to do this:
Eg.
Find a number: 1234567 which i dunno which file and which folder
I do know which main folder it is in but it is hidden deep within a lot of subdir.

Is it possible to find the file? + output the lines that contain the results to a file ?

Using ksh. AIX version.

If u are curious why I need to do this, its for work purpose.

PLs help ! Thanks!
Smilie
# 2  
Old 05-17-2004
yes its possible and you actually have already hit on the solution! Use the find command! Example find . -exec grep "1234567" -print {} \; 2>/dev/null See man find for detailed information on using the find command.
# 3  
Old 05-17-2004
OKIE thats cool. So how do you using the 'find' command to search for a list of

1234567
1223574
5243673
2356464

numbers ?


Last edited by unnerdy; 05-17-2004 at 11:42 PM..
# 4  
Old 05-17-2004
Use a grep option to search a list of occurences. See man grep for that. Or you could search one at a time (though it wouldnt be particularly fast if you searched a large directory tree). Remember that find is by nature, recursive. It will search from the directory that you specify down the tree and across file systems (unless you tell find otherwise). See the man pages for find and grep for greater detail. Also if you are searching many directories you will want to use xargs with find.

Last edited by google; 05-18-2004 at 08:36 AM..
# 5  
Old 05-24-2004
One performance refinement to google's method when the number of files is large is to do something like this:

find . -type f | xargs egrep '1234567|1223574|5243673|2356464'

There are three features to this:[list=1][*]Use "-type f" to not grep directories as files, etc.[*]Pipe the result through xargs to get as many files per grep as your OS/shell allows[*]Use egrep to search multiple patterns[/list=1]

ISTR there are versions of grep that will read a pattern list from a file --- consult your man pages.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Finding matching patterns in two files

Hi, I have requirement to find the matching patterns of two files in Unix. One file is the log file and the other is the error list file. If any pattern in the log file matches the list of errors in the error list file, then I would need to find the counts of the match. For example, ... (5 Replies)
Discussion started by: Bobby_2000
5 Replies

3. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

4. Shell Programming and Scripting

Echoing only once for each subdir

I have a script that runs from this: for i in * ; do (cd $i && echo $i && /test1/execute/testb);done this is testb: for file in `ls *.txt` do if && && && && && ; then echo "NO"; break 1; else echo "it is there" fi done What is happening is that I can get it to run a... (19 Replies)
Discussion started by: newbie2010
19 Replies

5. Shell Programming and Scripting

Finding files which contains anyone from the given patterns

Hi All, I need help as i am not able to create shell script for a scenario. i have 3000 numbers and want to search all the files which contain anyone of the above pattern. the files are in folder structure. Thanks and Regards Rishi Dhawan (14 Replies)
Discussion started by: Rishi26
14 Replies

6. Shell Programming and Scripting

Copy files from subdir

Hey, How can I copy files from subdirectories without copy the subdir and copy it to a higher dir For example: /home/test/subdir/file1 copy file1 to /home or another dir thanx (11 Replies)
Discussion started by: Eclecticaa
11 Replies

7. Shell Programming and Scripting

Finding several patterns and outputting 4 lines after

I an trying to parse a file looking for pattern1, or pattern2, or pattern3 and when found print that line and the next 4 lines after it. I am using korn shell script on AIX and grep -A isn't available. (1 Reply)
Discussion started by: daveisme
1 Replies

8. Shell Programming and Scripting

Finding patterns in a file

Hi, I have a file with 3 columns and I want to find when the average number of rows on column 3 is a certain value. The output will be put into another file indicating the range. Here is what I mean (file is tab separated): hhm1 2 0 hhm1 4 0.5 hhm1 6 0.3 hhm1 8 -1.4... (2 Replies)
Discussion started by: kylle345
2 Replies

9. Shell Programming and Scripting

Need help with awk tool - finding text between two patterns

This is regarding using awk tool to find lines matching between 2 patterns. cat file | awk '/pat1/,/pat2/' But it's not working as expected in the following case. If pat1 also comes after pat2 then it's matching whole file after pat1. e.g. # > cat -n file 1 First line... (3 Replies)
Discussion started by: anand_bh
3 Replies

10. Shell Programming and Scripting

finding and removing patterns in a large list of urls

I have a list of urls for example: Google Google Base Yahoo! Yahoo! Yahoo! Video - It's On Google The problem is that Google and Google are duplicates as are Yahoo! and Yahoo!. I'm needing to find these conical www duplicates and append the text "DUP#" in from of both Google and... (3 Replies)
Discussion started by: totus
3 Replies
Login or Register to Ask a Question