- test.txt
he is arat
he is in a rut
the food is Rotten
I like root beer
以下的命令都会针对test.txt进行。
1.匹配一个r接着任何一个字符再接着一个t的所有字符串(正则表达式对大小写敏感,故最后结果中不会出现R.t的)
grep r.t test.txt
2.匹配R和r接着任何一个字符再接着一个t的所有字符串
grep [Rr].t test.txt
3.匹配所有开头为he的
grep ^he test.txt
4.匹配所有包含he的字符串,但是排除she和the([^st] 方括号代表排除,[^st]代表排除开头为s和t的)
grep [^st]he test.txt