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
Release: 2024-01-04 16:41:41
forward
1359 people have browsed it

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行
Copy after login

The way to check the grep version number is

grep -V
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template