How can I make grep read the expression from standard input (stdin)?
For example (the following doesn't work):
grep -i -f &0 /path/to/text/file < "/regexp/"
While in the later case when you just do grep 'something' , there no file name given and hence grep will read its STDIN for input, no pipe is involved here so you need to type something on the STDIN (give input) to see the output. As you can see grep matched 46 from my typed contents and showed it on STDOUT.
The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.
The -n ( or --line-number ) option tells grep to show the line number of the lines containing a string that matches a pattern. When this option is used, grep prints the matches to standard output prefixed with the line number.
Use -f
with a single dash to denote the standard input:
$ echo Content | grep -f - notice.html <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> ...
Note: This has been tested with GNU grep - I am not sure if it's specified by POSIX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With