Get greatest revision

I have a few perl files that work to ultimately generate a text file.
I need to parse this file, gettting only the greatest revision of any given file.

The content of the text file to parse looks like this:

p4 integ -b BRANCH -s "//file/in/repository/filename.file#1" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/filename.file#2" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/filename.file#3" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/othername.file#1" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/othername.file#2" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/daname.file#1" //... >> log.txt

Only the file has thousands of entries similar to this...
What I need to parse out into a new text file would be the following:

p4 integ -b BRANCH -s "//file/in/repository/filename.file#3" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/othername.file#2" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/daname.file#1" //... >> log.txt

It's a real pain and fairly error prone to do this manually, and I know Perl and EE have the power to help!

Thanks for any help you can provide...
-J

jwcorbettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
Two questions:

1.  Does the //file/in/repository path vary?

2.  Are the revisions in order from oldest to newest?  ie: are later revisions always listed after the earlier revisions?
ozoCommented:
while( <> ){
   $p{$1}=[$.,$_,$2] if /"(.*)#(\d+)"/ && (!$p{$1} || $p{$1}[2]<$2);
}
print $_->[1] for sort{$a->[0] <=> $b->[0]} values %p;
TintinCommented:
ozo.

Not your usual one liner?  ;-)
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

ozoCommented:
It could be squeezed into one line, but I'd rather wait for the answers to your questions to see if it could be simplified first.
ZiaTioNCommented:
ozo,

I believe your example can already be shortened a bit:

while( <DATA> ){
   $p{$1} = $_ if (/".*?#(\d+)"/ && (!$p{$1}));
}
print $p{$_} for reverse sort(keys %p);

;-)
ZiaTioNCommented:
s/DATA//;
manav_mathurCommented:
Ziation, have a look at what your code produces and what is expected.

perl -ne '/(.*)#(\d+)/&&($2>($p{$1}{'val'}||0))&&do{$p{$1}{'lin'}=$_;$p{$1}{'val'}=$2}END{print $p{$_}{'lin'} foreach(keys %p)}' /path/to/source_file
manav_mathurCommented:
oops sorry....quotes gone awry!!

perl -ne '/(.*)#(\d+)/&&($2>($p{$1}{val}||0))&&do{$p{$1}{lin}=$_;$p{$1}{val}=$2}END{print $p{$_}{lin} foreach(keys %p)}' /path/to/source_file


On windows, just replace the 2 surrounding single quotes with double quotes.
jwcorbettAuthor Commented:
Yes, the file in repository path may change.
And I used 'sort' on the text file results, although that puts it in a not so sorted order ...if a file has 12 revisions, it would be listed in the text file as:
file#1
file#10
file#11
file#12
file#2
file#3
etc...
Thanks for all the help so far!
ZiaTioNCommented:
Ahh yes, I did not see the difference in filename in the example.  Good eye.
manav_mathurCommented:
>Yes, the file in repository path may change.

Then what should happen in the below case

p4 integ -b BRANCH -s "//file/in/repository/filename.file#1" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repository/filename.file#2" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repositorynew/filename.file#3" //... >> log.txt

Should the output be two entries?? namely
p4 integ -b BRANCH -s "//file/in/repository/filename.file#2" //... >> log.txt
p4 integ -b BRANCH -s "//file/in/repositorynew/filename.file#3" //... >> log.txt

Or do we have to _NOT_ consider the directory in question and create just one entry??
jwcorbettAuthor Commented:
Yes, I would need the two entries in that example.
ozoCommented:
the code in http:#14392835 produces the required two entries in that example, and handles revisions listed in the text file as:
file#1
file#10
file#11
file#12
file#2
file#3
manav_mathurCommented:
In my code, a new entry is created whenever any part of
p4 integ -b BRANCH -s "//file/in/repository/filename.file
changes

In http:#14392835, the entry is created whenever any part of
//file/in/repository/filename.file
changes.

However,
perl -ne '/"(.*)#(\d+)"/&&($2>($p{$1}{val}||0))&&do{$p{$1}{lin}=$_;$p{$1}{val}=$2}END{print $p{$_}{lin} foreach(keys %p)}' /path/to/source_file

works similar to http:#14392835

Manav

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jwcorbettAuthor Commented:
Thanks for all your help!
I'm still verifying what will work best, just wanted to drop a line letting you all know I appreciate your efforts and that they don't go to waste!
-J
jwcorbettAuthor Commented:
Thanks for all your help!
ozo's logic seems to be working best right now, although Manav's helped too!
EE Experts to the rescue once again!
Very grateful,
-J
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.