[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Search a string in a file

I need to search in a long file for occurences of a given string.

Using grep i get just the line where the string is present.

How do i visualize an interval which starts from N lines before and stop M lines after my string ?

0
RomanRega
Asked:
RomanRega
1 Solution
 
byttaCommented:
"grep --help" has the answer...

Context control:
  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context

So it's:
grep -BN -AM
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now