编程知识 cdmana.com

Linux grep view the top and bottom lines of the specified content

linux In the system , You can use grep View the specified content ,
such as :grep “123” test.log // see test.log Contained in the 123 Log of characters

If you want to see the top and bottom lines of the specified content , You can refer to the following usage :

$grep -10 ‘123’ test.log// Print before and after matching lines 10 That's ok
or
$grep -C 10 ‘123’ test.log// Print before and after matching lines 10 That's ok
or
$ grep -A 10 -B 10 ‘123’ test.log // Print before and after matching lines 10 That's ok

$grep -A 10 ‘123’ test.log // After printing the matching line 10 That's ok

$grep -B 10 ‘123’ test.log// Print the first... Of the matching line 10 That's ok

Other examples :
// Show both match ‘123’ Match again ‘456’ The line of
grep ‘123’ test.log| grep ‘456’

// Search for test.log Meet in 123 The line number of the content of
grep -n ‘123’ test.log

// see test.log The content after the specified line number , such as 50 That's ok
tail -n +50 test.log

// see test.log Of the 50 Row to 100 That's ok
sed -n ‘50,100p’ test.log# Remember p Letter

The detailed usage can be checked :http://blog.csdn.net/lychbeyond/article/details/41042483

版权声明
本文为[SVD]所创,转载请带上原文链接,感谢

Scroll to Top