 |
 |
Searching for a string in text files
|
 |
|
 |
|
Junior Member
Join Date: Nov 2003
Status:
Offline
|
|
Hi all,
I am currently looking for string in file usng the following command:
find (dir) -exec grep -l 'string' {} \;
This, however, also tries to look (and succeeds, I must say) into binary files. Is there a way to make this command only look into text files?
I am thinking along filtering what find finds through 'file' and then grepping for text, but lining the commands and pipes is beyond me at this point.
Any ideas?
Many thanks in advance,
_nmk
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
Not a bullet-proof suggestion, but *often* non-binary files end in .pl, .txt, etc...
grep -i foo *.*
would only search files of the format xxxx.yyy and skip most compiled binaries (which generally have no extension). The -i makes the search case insensitive.
Mike
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2002
Location: Germany/Heidelberg or Germany/Dresden
Status:
Offline
|
|
Originally posted by _nmk:
Hi all,
I am currently looking for string in file usng the following command:
find (dir) -exec grep -l 'string' {} \;
This, however, also tries to look (and succeeds, I must say) into binary files. Is there a way to make this command only look into text files?
I am thinking along filtering what find finds through 'file' and then grepping for text, but lining the commands and pipes is beyond me at this point.
Any ideas?
Many thanks in advance,
_nmk
Perhaps the option '-type' for the find command fits to your needs. Also the command file might be useful.
Kind regards, Lars
|
|
|
| |
|
|
|
 |
|
 |
|
Registered User
Join Date: Oct 2003
Status:
Offline
|
|
You could use 'find' with 'file' and write a short script, but here's a simple one-liner:
find dir -type f \( -name '*.txt' -o -name '*.cpp' -o -name '*.hpp' \) -exec grep -l 'string' {} \;
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
Originally posted by _nmk:
Hi all,
I am currently looking for string in file usng the following command:
find (dir) -exec grep -l 'string' {} \;
This, however, also tries to look (and succeeds, I must say) into binary files. Is there a way to make this command only look into text files?
I am thinking along filtering what find finds through 'file' and then grepping for text, but lining the commands and pipes is beyond me at this point.
Any ideas?
Many thanks in advance,
_nmk
According to `grep' man page `grep -I' treats binary files as if they contained no match... so... I'm not quite sure why you are having problems? Or what exactly is your problem 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|