Posted By: Mark Harrison
I would like to
grep for a string, but also show the preceding five lines and the following five lines as well as the matched line. How would I be able to do this?
For BSD or GNU
grep you can use
-B num to set how many lines before the match and
-A num for the number of lines after the match.
grep -B 3 -A 2 foo README.txt
If you want the same number of lines before and after you can use
grep -C 3 foo README.txt
This will show 3 lines before and 3 lines after.
Answered By: Pat Notz
- How do SO_REUSEADDR and SO_REUSEPORT differ?
- What is your most productive shortcut with Vim?
- What are the undocumented features and limitations…
- How do i calculate total without manually inputting it?
- Why cat does not work with parameter -0 in xargs?
- Java scanner taking inputs infinitely
- Usage of __slots__?
- How the int.TryParse actually works
- Confusion with Haskell classes
- What is the origin of foo and bar?
- Logging best practices
- Memcached vs. Redis?
- How can I manually compile a svelte component down…
- center 3 items on 2 lines
- What's the best way of scraping data from a website?
- For every line in a file, determine if string is…
- What does "Fatal error: Unexpectedly found nil while…
- How can I exclude all "permission denied" messages…
- How can I find the product GUID of an installed MSI setup?
- ExpressJS How to structure an application?
- Fast way of finding lines in one file that are not…
- python 3.2 UnicodeEncodeError: 'charmap' codec can't…
- What is an optional value in Swift?
- Design DFA accepting binary strings divisible by a…
- SQL query return data from multiple tables
- SQL Query for Student mark functionality
- Gnuplot line types
- What is a NullReferenceException, and how do I fix it?
- Smart way to truncate long strings
- Start redis-server with config file
- C free(): invalid pointer
- How to use Regular Expressions (Regex) in Microsoft…
- How to prevent scrolling the whole page?
- "Thinking in AngularJS" if I have a jQuery background?
- The definitive guide to form-based website authentication
- Print series of prime numbers in python
- Ukkonen's suffix tree algorithm in plain English
- Identifying and solving…
- Why does C++ code for testing the Collatz conjecture…
- Getting started with Haskell
- How to paste yanked text into the Vim command line
- "omp parallel for" does not work in "omp parallel"
- Getting the closest string match
- Aligning equations with multiple marks and lineups…
- Convert Little Endian to Big Endian
- #define macro for debug printing in C?
- Error message "Forbidden You don't have permission…
- Segmentation fault - invalid memory reference…
- Flex: REJECT rejects one character at a time?
- How do you clear the SQL Server transaction log?
- Checkout another branch when there are uncommitted…
- grep --ignore-case --only
- Deletion of an element of an array
- Why do I have to "git push --set-upstream origin "?
- Database development mistakes made by application developers
- List subfolders in sidebar navigation
- What are the real-world strengths and weaknesses of…
- Why do we use __init__ in Python classes?
- What is the worst programming language you ever worked with?
- java.sql.SQLException: - ORA-01000: maximum open…
- PHP parse/syntax errors; and how to solve them
- How to horizontally align ul to center of div?
- Tokenize mathematic string expression
- How to use Servlets and Ajax?
- How does PHP 'foreach' actually work?
- Reliable way for a Bash script to get the full path…
- How to recover stashed uncommitted changes
- How do I ignore files in Subversion?
- Programmatically Lighten or Darken a hex color (or…
- What are the nuances of scope prototypal /…
- What's the difference between eval, exec, and compile?
- How to make a SIMPLE C++ Makefile
- data.table vs dplyr: can one do something well the…
- What does a "Cannot find symbol" or "Cannot resolve…
- Capturing Groups From a Grep RegEx
- How to filter a RecyclerView with a SearchView
- How do I return the response from an asynchronous call?
- How do you run a command for each line of a file?
- How do you parse and process HTML/XML in PHP?
- How do I add files and folders into GitHub repos?
- How to generate a random string of a fixed length in Go?
- Virtual Memory Usage from Java under Linux, too much…
- PHP recursive function not allowing page to load
- Do you (really) write exception safe code?
- Can't update data-attribute value
- Understanding While Loops and Counter - How does it work?
- What is the difference between Cygwin and MinGW?
- What encoding/code page is cmd.exe using?
- Using Auto Layout in UITableView for dynamic cell…
- What is ROWS UNBOUNDED PRECEDING used for in Teradata?
- Reference - What does this regex mean?
- grep regex whitespace behavior
- Debugging the error "gcc: error:…
- What are the calling conventions for UNIX &…
- Round number to nearest integer
- What is an IndexOutOfRangeException /…
- How to dispatch a Redux action with a timeout?
- How to detect if multiple keys are pressed at once…