Avatar of klyles95
klyles95

asked on 

Extract a few lines from a large file

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.
PerlRegular ExpressionsLinux OS Dev

Avatar of undefined
Last Comment
klyles95
Avatar of ozo
ozo
Flag of United States of America image

grep -A 10 12345678 file
Avatar of klyles95
klyles95

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of klyles95
klyles95

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ozo
ozo
Flag of United States of America image

perl -ne 'print if $.=(/12345678/..4)'
Avatar of klyles95
klyles95

ASKER

thank you for responding
Avatar of klyles95
klyles95

ASKER

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
Perl
Perl

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

26K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo