Search for string in a directory with binaries exclusion


 
Thread Tools Search this Thread
Operating Systems Solaris Search for string in a directory with binaries exclusion
# 1  
Old 12-02-2008
Search for string in a directory with binaries exclusion

Hi all,

My need is to search for a given string "toto" within a directory, but the search should ignore binary and db files.

It is in fact, a combination of xargs grep that I didn't succeed to manage.
Let we say that we are under /etc/ and we want to search for all included files (except binary and db) that contain the string "toto". What will be the command?

Can someone help me please.

Thanks.
# 2  
Old 12-02-2008
/usr/sfw/bin/ggrep will do this
Use options:
-R (for recursive)
--binary-files=without-match (ignore binary files)
# 3  
Old 12-02-2008
If you have GNU grep:

Code:
grep -I

Regards
# 4  
Old 12-02-2008
Quote:
Originally Posted by Franklin52
If you have GNU grep:

Code:
grep -I

Regards
/usr/sfw/bin/ggrep is GNU grep Smilie
And yes the -I flag is the same as "--binary-files=without-match"
# 5  
Old 12-02-2008
i prefer the use of `egrep` as i have found it to be faster in my scripts then `grep`.
# 6  
Old 12-03-2008
Thanks Sed, but I cannot find ggrep on my solaris 10 installation, is there a dedicated package or an installation option? We have here 3 solaris 10 servers, and I can't find this command on any.
# 7  
Old 12-03-2008
Hi Pupp,
can you give me an example how to use the egrep? Let's try with the example given in my fist post : we are under /etc/ and we want to search for all included files (except binary and db) that contain the string "toto".

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search strings from a file in files in a directory recursively; then print the string with a status

Hi All, I hope somebody would be able to help me. I would need to search a string coming from a file, example file.txt: dog cat goat horse fish For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies

2. UNIX for Beginners Questions & Answers

Search directory for string and print file name

Good Evening Folks - I have a need to search a specific directory and ALL sub-directories for the following string: Data Load UpdatedIf this string is found, I need to print content from the line directory above it between symbols, as well as the file name where it is found. Here is a... (1 Reply)
Discussion started by: SIMMS7400
1 Replies

3. Shell Programming and Scripting

How to search for a string in all the files irrespective of directory.?

Hi All, How to search for a string in all the files irrespective of directory. If I use grep -i 'hello' *.* It will search for the string hello in the files of current directory. But I want to check for the string hello in the files of all the directories. Thanks (4 Replies)
Discussion started by: ROCK_PLSQL
4 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

6. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

7. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

8. UNIX for Dummies Questions & Answers

Searching a file with exclusion in the search

Hello, I'm looking for a bit of help. Im trying to search a file for lines that contain white spaces at the end of the lines. This is what I'm using where $param is the path and file name and it redirects the output to a txt file : echo | grep -n ' $' $param >> $2 Is it possible to have... (8 Replies)
Discussion started by: gintreach
8 Replies

9. UNIX for Dummies Questions & Answers

Unix find command to print directory and search string

Hi i need to print pathname in which the string present using 'find' command sample output like this Pathname String to be searched ---------- -------------------- /usr/test/myfile get /opt/test/somefile get Thanks in... (4 Replies)
Discussion started by: princein
4 Replies

10. Shell Programming and Scripting

Exclusion List of file and directory

dear all i trying to list all files within a directory. I want to exclude all subdirectory and some files, with using below statement, but it not exclude the files which start with "&" and end with "SL" , is there any things wrong with the below statement ? TIA cd /myaccount/mydirectory... (6 Replies)
Discussion started by: ayang
6 Replies
Login or Register to Ask a Question