Home >System Tutorial >LINUX >Introducing how to use the grep command to display context information under Linux

Introducing how to use the grep command to display context information under Linux

WBOY
WBOYforward
2024-01-04 16:41:411349browse

This article mainly studies the related content of grep displaying several lines of information before and after under Linux, as follows.

Grep under standard unix/linux controls the context through the following parameters grep -C 5 foo file displays the line matching the foo string in the file file and the upper and lower 5 lines grep -B 5 foo file displays foo and the first 5 lines grep -A 5 foo file Display foo and the next 5 lines to check the grep version number is grep -V. If you want to upgrade, the upgrade method: the latest source code (Google or Baidu search homepage), compile and install it somewhere, such as /home/ aaa/bin/ Then use /home/aaa/bin/grep when using it in the future, or just add /home/aaa/bin to the PATH environment variable.

grep under standard unix/linux controls the context through the following parameters

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

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

grep -A 5 foo file 显示foo及后5行

The way to check the grep version number is

grep -V

If you want to upgrade, the upgrade method: the latest source code (google or Baidu search homepage), compile and install it somewhere, such as /home/aaa/bin/, then use /home/aaa/ when you use it in the future. bin/grep, or add /home/aaa/bin to the PATH environment variable. Assuming you overwrite the latest compiled grep to the folder where your current grep is located, the upgrade will naturally be completed.

The above is the detailed content of Introducing how to use the grep command to display context information under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete