Link to home
Start Free TrialLog in
Avatar of mannn
mannn

asked on

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

SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perl -ne "print if (/^abcd\b/.../^/)==2"
Avatar of ghostdog74
ghostdog74


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

Open in new window

perl -ne 'print if $c;$c=/abcd/'  file
Avatar of mannn

ASKER

Thank you all of you, mrjoltcola,adam314,ozo and ghost dog74