LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep -I (https://www.linuxquestions.org/questions/linux-newbie-8/grep-i-670302/)

gustavolinux 09-16-2008 12:22 PM

grep -I
 
people, I'm studying grep, but did not understand the -I parameter...

Man grep says:

"Process a binary file as if it did not contain matching data;
this is equivalent to the --binary-files=without-match option."

what it means? Any file should be processed like this (as if it did not contain matching data) right? What it means to process a file as if it did contain matching data?

thanxs

jan61 09-16-2008 02:19 PM

Moin,

it means, that binary files are not grepped and don't flood your output with matching messages. Sometimes you want to do a grep pattern * to search for a pattern in a directory containing text and binary files. If you are not interested in matching results from binary files, the -I option helps you to ignore such files.

You can try this in /usr/bin, which contains a mix of shell scripts and binaries. Do a grep print * with and without this option. You'll see the difference.

Jan

pixellany 09-16-2008 02:28 PM

This is the part of the man page that tells the story:
Code:

--binary-files=TYPE
              If the first few bytes of a file indicate that the file contains
              binary data, assume that the file is of type TYPE.  By  default,
              TYPE  is  binary,  and  grep  normally outputs either a one-line
              message saying that a binary file  matches,  or  no  message  if
              there  is no match.  If TYPE is without-match, grep assumes that
              a binary file does not match;  this  is  equivalent  to  the  -I
              option.  If TYPE is text, grep processes a binary file as if it
              were text; this is equivalent to the -a option.  Warning:  grep
              --binary-files=text  might output binary garbage, which can have
              nasty side effects if the  output  is  a  terminal  and  if  the
              terminal driver interprets some of it as commands.

Try it on some binary files...First do "cat filename|hexdump -C|more" to see what text strings are there, and then run grep with the different options.

jan61 09-16-2008 03:10 PM

Moin,

no, THIS is the only important man page part:
Quote:

Originally Posted by pixellany (Post 3282307)
..If TYPE is without-match, grep assumes that a binary file does not match; this is equivalent to the -I option....

All files, which are assumed to be binary by grep, do not output a message about matches. The effect is, that you could grep a number of files without having to take care about unwanted "Binary file /usr/bin/a2p matches" messages.

It's not a question of different binary types.

Jan

gustavolinux 09-16-2008 03:42 PM

ok, i think I understood...

I could use -a together with -I ?

in case I dont want this "matches"messages in my output, but i do want to "scan" binary files?

tanx again

jan61 09-16-2008 03:56 PM

Moin,

try it! At my experience it will not work - the options are mutually exclusive. You say "I want binary files to be scanned" and next "I don't want to see binary file's output". The -a option handles binaries like text files (search for a newline or so) and would produce an output you normally do not want to see.

Find out what you get when using the different options. You will not nearly understand what all the options do, if you don't try it on a "real world" system.

Jan

gustavolinux 09-17-2008 08:19 AM

really... the command

grep -a -I 'umask.*mask' ./testetemp.iso

did nothing... mutually exclusive parameters, really...

tanx dudes


All times are GMT -5. The time now is 05:19 AM.