Search code examples
bashgrepcygwin

How do I interpet output from grep?


I'm running grep on Windows 7 via Cygwin, and I'm new to it. I just ran it on a file, and the only output that I got back was the filename that I ran it on. Does this mean it failed to find the specified string in the file? The output it gives seems to be bare at best; confusing at worst, and I haven't been able to find this documented anywhere, apart from how it will look like when given certain options.

What will be printed if grep has found the right string? What will be printed if it hasn't?


Solution

  • @Hashim:

    What will be printed if grep has found the right string? What will be printed if it hasn't?

    Let's say you are using a simple grep (without any regex or any other options)then it's line will be printed when a match for search string is found, let's see an example here. Let's say this is our file called Input_file.

    cat  Input_file
    test name etc xyz abc
    chumma hero type film
    
    grep "test" Input_file
    test name etc xyz abc    ---> Output
    
    grep "fill" file445
    NO Output as no match found.
    

    Also if you are using grep -l option then it will show the Input_file if a string is found in Input_file.