Cut Data In Bigfile with Perl

I want to create new file for START-END
but i know NO 0003/02 only one in file

Ex. Data FILE Data.txt (Data ~1,000,000 Line)

I use Script perl

perl -lne '$/="END";print $_."END" if /0003\/02/' file

Out put script perl

but I want create Out put All No in START-END have NO 0003/02 Please Help
Thank you

by awk

awk ' /^START/ {s=""} /NO 0003\/02/ {p=1} /^END/&&p {print s RS $0;p=0} {s=s RS $0}' infile

Error
and awk Slow in Data > 1,000,000 Line
i want use perl Script

in solaris, use nawk or /usr/xpg4/bin/awk

Script nawk is OK thank you
Please help Edit in perl Script

 nawk '/^START/ {s=""} /NO 0003\/02/ {p=1} /^END/&&p {print s RS $0;p=0} {s=s RS $0}' gg.txt
perl -lne '$/="END";print $_."END" if /0003\/02/' file

For the above code END matches with SUBEND

So you add carriage return (\n) in your code

perl -lne '$/="\nEND";print $_."\nEND" if /0003\/02/' file

Is it ok?

A perl one:

perl -ne '$a=$a.$_;if(/^START/){$a=$_;$i=1}if(/NO 0003\/02/){$p=1};if (/^END/ && $i && $p){print $a;$p=0}' infile

Thank you Very muck Script it OK

---------- Post updated at 04:23 PM ---------- Previous update was at 04:21 PM ----------

Thank you (kob khun Krab in thai style):smiley:

And yet another Perl script -

$
$
$ cat f33
START
NO 0001/01
HEAD AAAA
BODY1 AAA
TAIL AAA
END
START
NO 0001/03
HEAD AAAA
BODY1 AAA
BODY2 AAA
TAIL AAA
END
START
SUBSTART
NO 0002/02
HEAD AAAA
BODY1 AAA
BODY4 AAA
TAIL AAA
SUBEND
SUBSTART
NO 0003/02
HEAD AAAA
BODY1 AAA
BODY2 AAA
TAIL AAA
SUBEND
SUBSTART
NO 1005/02
HEAD AAAA
BODY1 AAA
TAIL AAA
SUBEND
END
START
NO 0004/01
HEAD AAAA
BODY1 AAA
BODY2 AAA
BODY3 AAA
BODY4 AAA
TAIL AAA
END
START
NO 0006/02
HEAD AAAA
BODY1 AAA
BODY2 AAA
TAIL AAA
END
$
$ perl -lne 'BEGIN{$/=""} /^.*\n(START.*?NO 0003\/02.*?\nEND).*$/s && print $1' f33
START
SUBSTART
NO 0002/02
HEAD AAAA
BODY1 AAA
BODY4 AAA
TAIL AAA
SUBEND
SUBSTART
NO 0003/02
HEAD AAAA
BODY1 AAA
BODY2 AAA
TAIL AAA
SUBEND
SUBSTART
NO 1005/02
HEAD AAAA
BODY1 AAA
TAIL AAA
SUBEND
END
$
$

tyler_durden