cat a.txt | grep -ri '->'我想用文本箭头->来grep行。但是在linux shell中,-意味着一个选项的开始。
>表示通过管道输出到文件。
所以在执行了上面给出的命令后,我得到了错误
[root@rs169 document_root]# cat a.txt | grep -ri '->'
grep: invalid option -- '>'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.有没有人能告诉我怎么做才对?
发布于 2013-08-08 17:39:07
$ echo "->" | grep -- "->"
->发布于 2013-08-08 17:36:12
grep -ri '\->' a.txt应该能做到
[A]$ grep -ri '\->' a.txt
12 ->2
[A]$ cat a.txt
12 ->2
11
[A]$ sh -version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.发布于 2013-08-08 17:50:30
使用-e键显式声明模式:grep -rie '->'
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (-e is specified by POSIX.)https://stackoverflow.com/questions/18122558
复制相似问题