Perl Script

Hi guys iam trying to write an perl script which does the below

Please help me ,,,,,,,

if file contains 20 records

abcd
blablablablablablablablablabla...
efgh
blalabalablabla.....
abcd
blablablablablablablablablabla...
efgh
blalabalablabla.....
abcd
blablablablablablablablablabla...
efgh
blalabalablabla.....
abcd
blablablablablablablablablabla...
efgh
blalabalablabla.....
abcd
blablablablablablablablablabla...
efgh
blalabalablabla.....
...

I need the script which takes the line or record after the abcd  and writes in new file

new file should contain

blablablablablablablablablabla...
blablablablablablablablablabla...
blablablablablablablablablabla...
blablablablablablablablablabla...
blablablablablablablablablabla...

i need perl script which does this 
 
#!/usr/local/bin/perl
open (MYFILE, 'XYZ.txt');
 
open (OFILE, '>ABCT.txt');
while (<MYFILE>) {
if (string found )
print OFILE "$_"+1;/* I need the next record if the string mach */
}

Open in new window

mannnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrjoltcolaCommented:
I'm thinking someting like this will work.

while (<MYFILE>) {
  if(/^abcd\n(.*?)\n/s) {
     print QFILE "$1\n";
  }
}
0
Adam314Commented:

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
 
open(my $in, "<file1.txt") or die "Could not open input: $!\n";
open(my $out, ">file2.txt") or die "Could not open output: $!\n";
 
my $keep;
while(<$in>){
	if($keep) {print $out $_;$keep=0;}
	elsif(/abcd/) {$keep = 1;}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
perl -lne 'BEGIN{$/="abcd\n"}print if $.>s/($).*//ms'
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

ozoCommented:
perl -ne "print if (/^abcd\b/.../^/)==2"
0
ghostdog74Commented:

perl -ne 'print if $c && $c--;$c=1 if /abcd/' file

Open in new window

0
ozoCommented:
perl -ne 'print if $c;$c=/abcd/'  file
0
mannnAuthor Commented:
Thank you all of you, mrjoltcola,adam314,ozo and ghost dog74
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.