how to output lines of a text file surrounding a certain pattern

Posted on 2004-11-08
Last Modified: 2013-11-08
I have a bunch of Fortran files and they all have "common blocks" for their variables.  What Unix command do I need to type
to print out the 10 (this is an arbitrary number) above and the 10 lnes (arbitrary) below where the word "DATAPOOL"
appears in all of my files?  I'm looking for something like "grep ... | awk ... > MyVariableList.txt" but I don't remember unix very well.

Question by:dwcronin
    LVL 11

    Accepted Solution

    grep -A 10 DATAPOOL filename

    (-B 10 for the 10 lines before...)
    LVL 11

    Expert Comment

    oops, you wanted above and below...

    grep -A 10 -B 10 DATAPOOL filename

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
    This article will show, step by step, how to integrate R code into a R Sweave document
    The viewer will learn how to implement Singleton Design Pattern in Java.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now