Transfer from: http: //www.itokit.com/2013/0308/74883.html
linux system by printing the matched grep vertical lines
If you just want a few lines above and below the matching pattern, grep can be achieved.
$ Grep -5 'parttern' inputfile // print five lines before and after matching lines
Front $ grep -C 5 'parttern' inputfile // print matching rows 5 rows
After row 5 $ grep -A 5 'parttern' inputfile // print matching lines
$ grep -B 5 'parttern' inputfile // print the first 5 rows of matching lines
to view the mysql slow log ip address is 192.168.0.10 SQL statements sent from the back three rows
to view the mysql slow log ip address is 192.168.0.10 SQL statements sent from the back three rows
- tail -50 /usr/local/mysql/data/sql-slow.log |grep -3 '192.168.0.10'
Match one field php error log
2,tail -100 /data/logs/php/php_error_5.3.log | grep "Memcache::get()";
View a file line 5 and a line 10
sed -n '5,10p' filename so you can view only the fifth line of the file to the line 10.