[Solved] Grep within find command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Grep within find command
# 1  
Old 07-05-2013
[Solved] Grep within find command

Platform: AIX 6.1/ksh

Question1.
I want to grep for the string "CUSTOM_PKMS" in all the files in server except those files with extensions .dbf , .ctl and .dmp

I started running the following command but it is taking too long because there are lots of .dbf , .ctl and .dmp files in this server, some of .dbf and .dmp files being very large

Code:
find / -name "*"  -exec grep "CUSTOM_PKMS" '{}' \; 2>/dev/null

So, how can I skip files with extension .dbf , .ctl and .dmp for the above find command ?

Question2.
This string is more likely to be in a file without any extension
Example :
Code:
/var/log/messages

Is my above find command searching for files without extension as well ?
# 2  
Old 07-05-2013
The problem is it might even search in binaries (is it what you want?)
extensions .dbf , .ctl and .dmpare unwanted... but thos files are for a RDBMS no, Adn you know where they are... so its easier to no search in those file systems...
# 3  
Old 07-05-2013
So, any idea how I can skip the files with extension .dbf , .ctl and .dmp ?
# 4  
Old 07-05-2013
What are you looking for - for what purpose? Because if its a variable you want to see if set anywhere meaning you are looking for configuration files ( = ascii ) then avoiding binaries is wise... then if you have no reason to search in the RDBMS e.g. oracle files systems then, you dont search there also, if this variable is something system, then it must be in / or /usr meaning you have only 2 filesystem to parse and not that big if correctly written (search by filesystem...) because a find parsing from / everywhere on a big system can take quite some time and resource...
The more you give use information on what you are looking for (or/and why), more we can target the find you need...
# 5  
Old 07-05-2013
You can use unary NOT operator ! and AND operator -a
Code:
find / \( -name '*' -a ! -name '*.dbf' -a ! -name '*.ctl' -a ! -name '*.dmp' \) -type f -exec grep "CUSTOM_PKMS" '{}' +

This User Gave Thanks to Yoda For This Post:
# 6  
Old 07-05-2013
Being curious : How long did the execution last?....
# 7  
Old 07-05-2013
Thread closed since user refused to reply at asked question and got a one liner solution he wanted...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

[Solved] Find command hangs my terminal session

Hello every one. I know little to nothing about AIX. Recently I have been assigned to an AIX project. For some reason or another the find command is hanging the server. Well it does not hand server per say, it just freezes my terminal session. after running find, I waited up to 40 min and... (3 Replies)
Discussion started by: busi386
3 Replies

2. Shell Programming and Scripting

[Solved] Find command is not working

Hello Friends, I have a problem about a little script, when i run the following two lines one by one on CLI then they work well: /usr/bin/mkdir `perl -e 'use POSIX qw(strftime); print strftime "%Y-%m-%d",localtime(time() - 30*24*60*60);'` find . -type f -name "fuseesb.log.*" -mtime 30... (5 Replies)
Discussion started by: EAGL€
5 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Wildcards used in find, ls and grep commands

Platforms : Solaris 10 and RHEL 5.6 I always get double quotes , single quotes and asteriks mixed up for find, ls and grep commands. The below commands retrieve the correct results. But , unders stress , I get all these mixed up :mad: .So, i wanted to get a clear picture. Please check if... (7 Replies)
Discussion started by: John K
7 Replies

4. UNIX Desktop Questions & Answers

[SOLVED] find command match pattern

Hello, I would like to ask you, how to match directory names. I need to find only directories, which are created only from numbers and doesn't include any letters. I used command find $AC_WORKDIR/work_archive/test/$dirs_years -maxdepth 1 -name \\* -print If I have dirs like 12... (3 Replies)
Discussion started by: satin1321
3 Replies

5. UNIX for Dummies Questions & Answers

Find/grep Command

Kinldy help me to write the find command on following: There are different version of file 'abc.txt' located in many folders similar as below. /home/gupta/abc.txt /home/gupta/db/abc.txt /home/gupta/temp/abc.txt /home/gupta/db/test/abc.txt 1) I want to know... (4 Replies)
Discussion started by: ravigupta2u
4 Replies

6. UNIX for Dummies Questions & Answers

[Solved] weird in find -exec command

i feel weird with this 2 command find /tmp/*test* -user `whoami` -mtime +1 -type f -exec rm -f {}\; find /tmp/*test* -user `whoami` -mtime +1 -type f -exec ls -lrt {}\; the first one return correct which only delete those filename that consist *test* where second command it listed all the... (12 Replies)
Discussion started by: lsy
12 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Assistance with find command please

Trying to locate files less than xx days old, throughout all directories/subdirectories, but excluding certain types of directories and files. The directories I want to search all contain the same characteristic (dbdef, pldef, ghdef, etc), and there are subdirectories within that I need to... (2 Replies)
Discussion started by: Condmach
2 Replies

8. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

9. Shell Programming and Scripting

help in find and grep command !

i have some 2000 file. i need to grep a particular word in all those files and list the filename that contains it? grep -l '0008345923LG' *.* the above command is not working? giving o/p as arg list too long PLZ anyone help me Thnaks in advance (1 Reply)
Discussion started by: ali560045
1 Replies

10. UNIX for Dummies Questions & Answers

Find command with Grep

I need to find for a particular string in my /opt file system. find . -exec grep "10000" {} \; I tried this command, it works ok but I want not to search in the logs folder I have in my filesystem as it takes lot of time. SO can I exclude one or more than on directory or sub directories from... (10 Replies)
Discussion started by: venu_nbk
10 Replies
Login or Register to Ask a Question