Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^12: How do I use grep in a script

by Flintlock (Novice)
on Dec 27, 2017 at 18:12 UTC ( [id://1206285]=note: print w/replies, xml ) Need Help??


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

The test data posted by poj returns the expected results, so what can be the difference?

Replies are listed 'Best First'.
Re^13: How do I use grep in a script
by Flintlock (Novice) on Dec 28, 2017 at 15:49 UTC
    I have determined what the issue is attempting to add the "Name:" search.

    The Name: is actually on a separate line in the text file ie.

    STATUS Acct:142424 Disposition:9000 CANCEL Wait: 04/11/17 DEBTOR Name:LastName FirstName Ssn:123456789 Cbr: Ph:555.555.1212

    So I need to somehow grab both the LastName and the 142424 and concatenate then into LastName_142424_2017.txt

    while (<$fh>){ next unless /\S/; # skip blank lines if (/Acct:(\d+)/){ $acct = $1; if (/Name:([^\s]+)/){ $acct = $1.'_'.$acct; } } push @{$data{$acct}},$_ if ($acct); }
    But this does not take into account for the Name: search to be on another line and still keep ALL the text to be added to the new file.

    Any suggestions on how I can accomplish this?

      Are the account numbers unique such that you can build a mapping of account number => name ?

      my %name = (); . . while (<$fh>){ next unless /\S/; # skip blank lines if (/Acct:(\d+)/){ $acct = $1; } if (/Name:([^\s]+)/){ $name{$acct} = $1; } push @{$data{$acct}},$_ if ($acct); }
      my $outfile = join '_',$name{$acct},$acct,'2017.txt';
      poj
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1206285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-26 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found