Linux下的正则表达式(基础)

时间:2023-03-09 17:29:29
Linux下的正则表达式(基础)
grep -n 'the' text.txt
搜寻含有the的部分(n代表现实显示行号)
grep -vn 'the' text.txt
搜寻不含有the的部分(n代表现实显示行号)
grep -vn 't[ha]e' text.txt
搜寻含有the 或者 tae 的部分
grep -n '[^g]oo' text.txt
搜寻oo钱包不含有g的部分
grep -n '[a-z]oo' text.txt
搜寻含有小写字母的部分
grep -n'[^a-z]' text.txt
搜寻不含有小写字母的部分
grep -n '^the' text.txt
搜寻行首有the的部分
grep -n 'the$' text.txt
搜寻行尾有the的部分
grep -n 'go*' text.txt
搜寻g后面有1个以上o的部分
grep -n 'go\{2,5\}' text.txt
搜寻g后面有2到5个o的部分