• notice
  • Congratulations on the launch of the Sought Tech site

View the content of the lines before and after the keyword in the file

Sometimes the files are so large that we can't read them all to find what we want. At this time, we need a linux command to view the contents of a few lines before and after a keyword: grep

Using the help command of linux, as shown in the figure below, we can see the usage of grep. Here we pay attention to the display problem before and after the keyword.

426_b5a_776.jpeg

Take the file test.txt as an example,

1) Display the content of ten lines after the line where the keyword (eg: 16:55) is located: cat test.txt | grep -A10 16:55 (11 lines are displayed in total, the first line is the line where the keyword is located)

2) Display the content of ten lines before the line where the keyword (eg: 16:55) is located: cat test.txt | grep -B10 16:55 (11 lines are displayed in total, the 11th line is the line where the keyword is located)

3) Display the content of ten lines before and after the line where the keyword (eg: 16:55) is located: cat test.txt | grep -C10 16:55 (21 lines are displayed in total, the 11th line is the line where the keyword is located)


Tags

Technical otaku

Sought technology together

Related Topic

1 Comments

author

lipitor sale & lt;a href="https://lipiws.top/"& gt;buy lipitor 80mg pill& lt;/a& gt; order lipitor 80mg pills

Cafygz

2024-03-09

Leave a Reply

+