in reply to Re^14: How do I use grep in a script
in thread How do I use grep in a script

Yes Sir,

The Acct number is unique, however, the Name: tag is NOT. It does occur elsewhere within the block of text for that acct number.

Replies are listed 'Best First'.
Re^16: How do I use grep in a script
by poj (Abbot) on Dec 28, 2017 at 16:17 UTC

    Presumably the name is always the same within the block for that account. Try

    #!/usr/bin/perl use strict; my $acct; my %data = (); my %name = (); my $infile = 'Facs_Data.txt'; open my $fh,'<',$infile or die "Could not open '$infile' : $!"; while (<$fh>){ next unless /\S/; # skip blank lines if (/Acct:(\d+)/){ $acct = $1; } if (/Name:([^\s]+)/){ $name{$acct} = $1 unless defined $name{$acct}; } push @{$data{$acct}},$_ if ($acct); } close $fh; for my $acct (keys %data){ my $outfile = join '_',$name{$acct},$acct,'2017.txt'; print "Creating $outfile\n"; open my $fh,'>',$outfile or die "Could not open '$outfile' : $!"; for (@{$data{$acct}}){ print $fh $_; } close $fh; }
    poj
      Thanks poj This appears to be what I am looking to accomplish!!
        There is a glitch in the way Acct: is searched for.

        I need to delimit each record by "STATUS Acct:"

        My attempts are producing no results

        if (/\"STATUS Acct:\"(\d+)/)

        I think I would need to escape the quotes, but maybe not?

        I can grep this from the command line and get the correct results without escaping the quotes.

        Any Ideas?