cat /etc/passwd | grep -A5 root 文件passwd中查找包含root的后5行B是前n行,忘了是大写还是小写的A for afterB for before
比如上一行,下二行:grep -A 2 -B 1 'str' file
查找匹配的行数:$ grep -c "被查找的字符串" 文件名定位到第x行:$sed -n 'xp' 文件名
用grep命令的-A -B参数就可以得到相应的结果!