参数列表:
^:匹配以指定字符串开头的字符:
cat test.txt | grep ^s
$:匹配以指定字符串结尾的字符:
cat test.txt | grep f$
^$:匹配空行:
cat test.txt | grep -n ^$
[abc]:匹配字符集内任意一个字符:
cat test.txt | grep [^a]
[^abc]:匹配不包含指定字符的字符:
cat test.txt | grep -o [^a]
匹配非字母的任意行:
cat test.txt | grep [^a-z]
匹配非数字的任意行:
cat test.txt | grep [^0-9]
匹配指定字符出现n次:
cat test.txt | grep -E "a{2}" || cat test.txt | egrep a{3}
匹配指定字符最少匹配n次或最多匹配m次:
cat test.txt | grep -E "a{1,2}d"
匹配指定字符出现至少n次:
cat test.txt | grep -E "a{1,}"
匹配以指定字符开头以指定字符结尾的字符:
cat test.txt | grep s.*k