We help IT Professionals succeed at work.
Get Started

Extract a few lines from a large file

574 Views
Last Modified: 2012-05-11
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
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE