in reply to Re: Print text on the same line after match
in thread Print text on the same line after match
One detail that I forgot to mention, and I edited the original post, is that I am working on Windows with Strawberry Perl. I had some trouble integrating the command into my script and could not store the output into a variable as it just went to stdout due to the "print $1 if" portion. I tried to redirect stdout, and not using "print" at all, but I ended up creating a temp file using this code to store the resulting number in a variable:
Is there a better way to store the result into the variable?use IO::Handle; # Extract the Payee ID from the file and store it into a temporary fil +e my $payeeid; system( q(perl -ne "print $1 if /INC\*XX\*(\d+)/" cr835.txt > payee.tx +t) ); # Define a file variable and read the contents to a variable my $file; $file = path("./payee.txt"); my $payeeid = $file->slurp; # Define the date and time for use in the new file name use constant DATETIME => strftime("%Y-%m-%d_%H-%M", localtime); # Define the new file name my $file = "CR835.txt"; my $newfilename = "CR835-" . $payeeid . "-processed_" . DATETIME . ".t +xt"; # Rename the file move $file, $newfilename;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Print text on the same line after match
by haukex (Archbishop) on Dec 14, 2018 at 23:08 UTC |