0

I have a 2GB text file and I want to read every line 100 lines after a certain string is found example:

string: 'epicvar (string) ="5"'

string was found on line 5000 so I want to read the file from 5000 to 5100 then the string was also found on line 15000 so I want to read the file from 15000 to 15100 and so on.

The system used is HP-UX B.11.31 U

kvantour
  • 25,269
  • 4
  • 47
  • 72
  • Could you update tags indicating your OS? It looks like you are on Solaris or AIX – fedorqui Jul 17 '14 at 09:17
  • I would suggest compiling and installing [GNU grep](http://www.gnu.org/software/grep/) (perhaps with `./configure --prefix=$HOME/soft/` if you don't have root access) theu using the `grep -A100` as suggested in the deleted [answer by Fedorqui](http://stackoverflow.com/a/24799223/841108) – Basile Starynkevitch Jul 17 '14 at 09:31
  • company server :D can't do those installs as I please ...unfortunatly – Edmund Simpson Jul 17 '14 at 10:02

1 Answers1

2

This may work for you (untested), if you understand ll2p means last line to printit should be easy enough to read...

awk '/pattern/ {ll2p = NR+100}
        NR < ll2p {print}
        NR==ll2p {ll2p=0} ' file
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432