Extract a few lines from a large file

klyles95
klyles95 used Ask the Experts™
on
I have a large pipe delimited file with approx. 2.3 million rows (records).

I am attempting to locate a particular record.  However I do not have any information regarding the record of interest but I believe that I have information about a record that may be close to it.  So essentially I want to look for the record that I know about, once string is found, I'd like it to write the contents of that line plus a specified number of lines that follows the found string to see if I can identify my missing record.  

 How can I be looking for a record I don't know about?  It is based on counts.  I am missing a single record and based on what was inserted into a database I have pointed the last record that was inserted and I believe the record that is missing should have been inserted after that.

The record that I have information on commences with the following:
D|12345678

The numeric is a unique number.  So I want to be able to get the row where this text appears, output the entire line and print an additional say 3 - 10 lines (or how many lines I desire after) to see if I can locate the missing record.

I have been reading about grep, sed, awk and I am at a total loss how to implement.  I do not want to have to open such a large file and scan to this location in order to find my record.

Any help would be greatly appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
grep -A 10 12345678 file

Author

Commented:
Unfortunately, when I tried it I got the message that -A was an illegal option.  I looked up this option and it should have worked??

I am on a unix box SunOS.
Commented:
I have been able to locate my lines of interest with the following:

sed -n 1865838,1865850p\;1865851q filename >> myfile2.txt
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
perl -ne 'print if $.=(/12345678/..4)'

Author

Commented:
thank you for responding

Author

Commented:
Further searching of this forum and internet led me to take a deeper look at sed given that I could not use grep -A as proposed

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial