
yoda
New User
Jul 28, 2010, 2:48 PM
Post #1 of 4
(238 views)
|
|
Obtain beg/end numbers from previous lines
|
Can't Post
|
|
I'm very new to Perl and need help with a script I'm trying to create. I don't have a programming background, so please bear with me. I'm entering a sample of my original file and then a sample of the desired output below. The original file will be at least tens of thousands of lines, so not sure of the best way to read in the file. The "Y" character signals the StartNumber, and then the EndNumber will be the last id number before the next start. It's possible a start/end number will be the same, as in the example on the first line. Original file: ID0001,TEMP,\\DATA\Folder,Y,,, ID0002,TEMP,\\DATA\Folder,Y,,, ID0003,TEMP,\\DATA\Folder,,,, ID0004,TEMP,\\DATA\Folder,Y,,, ID0005,TEMP,\\DATA\Folder,,,, ID0006,TEMP,\\DATA\Folder,,,, ID0007,TEMP,\\DATA\Folder,,,, ID0008,TEMP,\\DATA\Folder,Y,,, ID0009,TEMP,\\DATA\Folder,,,, ID0010,TEMP,\\DATA\Folder,Y,,, Desired Output: StartNumber,Endnumber ID0001,ID0001 ID0002,ID0003 ID0004,ID0007 ID0008,ID0009 ID0010,ID0010 This is the script I have come up with so far, but it only obtains the start number.
open (TEXT, 'Input.txt'); while (<TEXT>) { chomp; ($pageid, $vol, $path, $docyes, $one, $two, $three) = split(","); if ($docyes eq "Y") { $Begnum = $pageid; print "$Begnum,\n" } next; } close (FILE); exit; Any help appreciated. Thanks
|