in reply to REGEX on multiple lines
When you do it that way, it's easier to automate multiple runs (extract a given pattern from several files, or several patterns from one file, or several patterns from several files, etc...), as well as being easier, quicker and less error-prone to run the script manually.#!/usr/local/bin/perl use strict; use warnings; my $Usage = "Usage: $0 search-pattern data.file\n"; ( @ARGV == 2 and -f $ARGV[1] ) or die $Usage; my ( $pattern, $ifile ) = @ARGV; open( IN, "<", $ifile ) or die "$ifile: $!\n$Usage"; $/ = "\n1"; # use FORTRAN page break as input record separator my $opattern = $pattern; $opattern =~ s/[^\w.-]/_/g; # limit range of characters to be my $ofile = "$ifile.$opattern"; # used in output file name open( OUT, ">", $ofile ) or die "$ofile: $!\n"; while (<IN>) { print OUT if ( /\n0 EID:\s+$pattern\s+/ ); } close OUT;
|
|---|