periodicalcoder has asked for the wisdom of the Perl Monks concerning the following question:
This is actually a follow-up of that same project, and while I feel that this should be simple I cannot find (or don't know enough to adapt) a solution online. I have a text file with a line (there will only ever be a single line that matches) like this:
N1*PE*COMPANY NAME INC*XX*123456~
**edit: on Windows using Strawberry Perl with a .pl script** I need to extract the number at the end of this line, excluding the tilde, and add it to a variable so that $number = 123456. So far I have only been able to come up with the match regex, but I'm not sure how to get the text at the end. So far I have this which gives the entire line:
perl -ne "print if /INC\*XX\*/" cr835.txt
Inside my perl script I assume that I will use something like this, but of course including any recommended code changes:
my $number = "perl -ne "print if /INC\*XX\*/" cr835.txt";
My end goal is to detect this number and use it to rename the file. I already have the code tested for renaming the file with a timestamp and I just need help populating this variable.
Thanks a bunch!
peridicalcoder
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print text on the same line after match
by haukex (Archbishop) on Dec 14, 2018 at 21:00 UTC | |
|
Re: Print text on the same line after match
by toolic (Bishop) on Dec 14, 2018 at 20:35 UTC | |
by periodicalcoder (Novice) on Dec 14, 2018 at 22:48 UTC | |
by haukex (Archbishop) on Dec 14, 2018 at 23:08 UTC | |
|
Re: Print text on the same line after match
by johngg (Canon) on Dec 14, 2018 at 23:57 UTC | |
by BillKSmith (Monsignor) on Dec 15, 2018 at 03:48 UTC | |
by johngg (Canon) on Dec 15, 2018 at 14:24 UTC | |
|
Re: Print text on the same line after match
by thanos1983 (Parson) on Dec 14, 2018 at 23:55 UTC |