rebkirl has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
In am new to Perl scripting. I have done some research for solving this question but I would need some help with the code.
I have the following file.txt (X and Y state for above and below text lines):
Further details:XXXXXXXXXX YYYYYYYY TIFF 1..203 /def="Z/AA:XGproxy1" /pattern="gdgdfn6N6" TIFF trans(256..298) /def="Z/AA:ZYprompt5" /pattern="HbgREV5ehe757gAH" TIFF trans(303..323) /pattern="hfftvt&&jdgY=)" XXXXXXXX YYYYYYYY
foreach $row (@file){ if ($row =~ /TIFF\s+([0-9.]+)/g){ @columns = split(/\s+../, $row); $difference = scalar(@columns[2]) - scalar(@columns[1]); print ("$difference\n"); } }
In addition I want to print all patterns in another file2.txt, taking part of definition (i.e. XGproxy1) as an header:
Example outputs:
>XGproxy1
gdgdfn6N6
>ZYprompt5
HbgREV5ehe757gAH
I tried the following code but it prints only the first pattern and I do not know how to print into FILE2.
open (FILE1, 'file1.txt'); open (FILE2, 'file2.txt'); $content =~ /pattern="([A-Z\s]+)/g; $query = $1; $query =~ s/\s+//g; print("$query\n”);
It would be very appreciated if anyone could give me some help with writing a proper code or point me in the correct direction.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract length sum from columns and print pattern into another file
by poj (Abbot) on Jun 07, 2019 at 14:32 UTC | |
by rebkirl (Acolyte) on Jun 07, 2019 at 15:13 UTC | |
by pryrt (Abbot) on Jun 07, 2019 at 15:36 UTC | |
by poj (Abbot) on Jun 07, 2019 at 15:23 UTC | |
|
Re: Extract length sum from columns and print pattern into another file
by stevieb (Canon) on Jun 07, 2019 at 16:02 UTC |