Shell之海量数据处理grep,cut,awk,sed

GREP

  grep命令是Globally search a Regular Expression and Print的缩写,表示进行全局的正则匹配并进行打印。grep的相关扩展命令包括egrep和fgrep,其中egrep支持更多的正则匹配,fgrep只进行字符的匹配,不支持正则表达式。

  

grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

OPTIONS
-n 匹配的行数也展示出来
-A 3 将匹配之后的3行也展示出来
-B 3 将匹配之前的3行业展示出来
-o 仅输出匹配的部分
-v 反向匹配
-f 指定需要匹配的文件


root@wdev02:/usr/local/shell# cat 1.txt 
123
345
root@wdev02:/usr/local/shell# cat 2.txt 
abc
bcd
123
haha
hehe
23456
hello
abcd
root@wdev02:/usr/local/shell# grep -n 3 2.txt 
3:123
6:23456
root@wdev02:/usr/local/shell# grep -w -n -f 1.txt 2.txt 
3:123
View Code

猜你喜欢

转载自www.cnblogs.com/ryjJava/p/12465221.html