0

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?

Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
  • Please include the command you ran, its output, and what your expected output was. – codeforester Feb 27 '17 at 02:17
  • This Q is not about programming as defined for StackOverflow. It **may** be more appropriate on the S.E. related site http://unix.stackexchange.com (Unix & Linux). Use the `flag` link at the bottom of your Q and ask the moderator to move it. Please don't post the same Q on 2 different sites. ***Please*** read http://stackoverflow.com/help/how-to-ask http://stackoverflow.com/help/dont-ask and http://stackoverflow.com/help/mcve before posting more Qs here. Good luck. – shellter Feb 27 '17 at 03:18
  • I'm not understanding why it's off-topic. Granted, shell scripting isn't programming in the strictest sense of the term, but it is in the broad sense of "coding" that is more commonly employed on this site, as evidenced by the fact it's regularly home to plenty of other [`bash`](http://stackoverflow.com/questions/tagged/bash) and [`grep`](http://stackoverflow.com/questions/tagged/grep) questions, a large portion of which do not relate directly to programming and have been well recieved. I'm failing to see what makes my question any different. – Hashim Aziz Feb 27 '17 at 14:19
  • My question seems to be no different from any of the following questions: [Grep A File But Show Several...](http://stackoverflow.com/questions/9081/grep-a-file-but-show-several-surrounding-lines?rq=1) [How To Concatenate String Variables...](http://stackoverflow.com/questions/4181703/how-to-concatenate-string-variables-in-bash) [How Can I Use Grep To Find A Word...](http://stackoverflow.com/questions/4121803/how-can-i-use-grep-to-find-a-word-inside-a-folder?rq=1) [How Do I Reload Bashrc...](http://stackoverflow.com/questions/2518127/how-do-i-reload-bashrc-without-logging-out-and-back-in) – Hashim Aziz Feb 27 '17 at 14:26

1 Answers1

1

@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.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93