Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2004-11-08
Medium Priority
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
  • 2
LVL 11

Accepted Solution

cjjclifford earned 2000 total points
ID: 12524311
grep -A 10 DATAPOOL filename

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

Expert Comment

ID: 12524319
oops, you wanted above and below...

grep -A 10 -B 10 DATAPOOL filename

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 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