Linux command: grep


How to use grep to match multiple strings in the same line?

grep 'string1\|string2' filename
grep -E "string1|string2" filename

How can I grep for a string that begins with a dash/hyphen?

1. Quote AND/OR escape
 ls | grep "\-a"
(that \ is the escape character)
2. Use flag "--" to stop switch parsing
ls | grep -- -a
posted @ 2017-12-02 07:18 emanlee 阅读(...) 评论(...) 编辑 收藏