[Linux-CMD]grep

# 显示file文件中匹配foo字串那行以及上下5行
grep -C 5 foo 

# 显示foo及前5行
grep -B 5 foo 

# 显示foo及后5行
grep -A 5 foo 
$ cat size.txt
b124230
b034325
a081016
m7187998
m7282064
a022021
a061048
m9324822
b103303
a013386
b044525
m8987131
B081016
M45678
B103303
BADc2345

$ cat size.txt | grep 'a022021'
a022021

$ cat size.txt | grep 'a022021' -C 2
m7187998
m7282064
a022021
a061048
m9324822

$ cat size.txt | grep 'a022021' -B 2
m7187998
m7282064
a022021

$ cat size.txt | grep 'a022021' -A 2
a022021
a061048
m9324822

你可能感兴趣的:([Linux-CMD]grep)