cat a.txt | grep -ri '->'
I want to grep lines with text arrow ->.
But in linux shell
-
means starts of an option
and
>
means pipe output to a file.
So after doing command given above ,I got error
[root@rs169 document_root]# cat a.txt | grep -ri '->'
grep: invalid option -- '>'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
Can someone tell how to do it correctly?
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 grep command prints entire lines when it finds a match in a file. To print only those lines that completely match the search string, add the -x option. The output shows only the lines with the exact match.
For BSD or GNU grep you can use -B num to set how many lines before the match and -A num for the number of lines after the match. If you want the same number of lines before and after you can use -C num . This will show 3 lines before and 3 lines after. Save this answer.
To find a pattern that is more than one word long, enclose the string with single or double quotation marks. The grep command can search for a string in groups of files. When it finds a pattern that matches in more than one file, it prints the name of the file, followed by a colon, then the line matching the pattern.
Another way of doing it is to use --
- this tells grep that you have finished using flags, and any -
appearing after this is to be interpreted literally.
$ echo "->" | grep -- "->"
->
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