Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:16:41+00:00 2026-06-13T18:16:41+00:00

GOAL:- I need to parse a file with the below input and get the

  • 0

GOAL:-
I need to parse a file with the below input and get the latest (builddate timestamp should be latest)location when the status is approved and builddate is the latest..I provided sample input and output,I have the code in perl,new to python,please suggest how can this be implemented in python

INPUT:-
Build:          M1234BAAAANAAW9321.1
Location:       \\dreyers\builds468\INTEGRATION\M1234BAAAANAA9321.1
Comments:       Build completed, labeled, and marked for retention.
Status:         Approved
BuildDate:      10/25/2012 12:51:25


Build:          M1234BAAAANAAW9321.2
Location:       \\crmbld01\Builds\FAILED\M1234BAAAANAA9321.2
Comments:       The build is currently in a failed status.
Status:         Failed
BuildDate:      10/25/2012 19:37:17


Build:          M1234BAAAANAAW9321.3
Location:       \\freeze\builds427\INTEGRATION\M1234BAAAANAA9321.3
Comments:       Build completed, labeled, and marked for retention.
Status:         Approved
BuildDate:      10/25/2012 19:43:28

OUTPUT:-\\freeze\builds427\INTEGRATION\M1234BAAAANAA9321.3

Following is the perl code that achieves,I am new to python,please suggest how can I pythonize this code

$ echo 'Build:          M1234BAAAANAAW9321.1
Location:       \\dreyers\builds468\INTEGRATION\M1234BAAAANAAW9321.1
Comments:       Build completed, labeled, and marked for retention.
Status:         Approved
BuildDate:      10/25/2012 12:51:25


Build:          M1234BAAAANAAW9321.2
Location:       \\crmbld01\Builds\FAILED\M1234BAAAANAAW9321.2
Comments:       The build is currently in a failed status.
Status:         Failed
BuildDate:      10/25/2012 19:37:17


Build:          M1234BAAAANAAW9321.3
Location:       \\freeze\builds427\INTEGRATION\M1234BAAAANAAW9321.3
Comments:       Build completed, labeled, and marked for retention.
Status:         Approved
BuildDate:      10/25/2012 19:43:28
' | perl -e'

local $/ = "";
my ( $build_date, $location );
while ( <> ) {
next unless /status:\s+approved/i;
my $date = sprintf "%04d%02d%02d%02d%02d%02d", ( /builddate:\s+(\d
++)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)\D+(\d+)/i )[ 2, 0, 1, 3, 4, 5 ];
if ( !defined $build_date || $build_date lt $date ) {
    ( $build_date, $location ) = ( $date, /location:\s+(.+)/i );
    }                                                           
}    

print “$location\n”;
‘
\freeze\builds427\INTEGRATION\M1234BAAAANAAW9321.3

I tried to write the following in python,doesnt seem to work,am wondering if there is a better implementation to achieve the goal..please suggest

for line_info in lines:

    line_info.find('Location')

    if line_info.find('Location') == 0:
        # Build Location
        print "  Found Build location"
        logString += "  Found Build location\n"
        location = line_info.split(" ")
        location1 = location[len(location)-1]
    elif line_info.find('Status') == 0:
        # Status
        print "  Found Status"
        logString += "  Found Status\n"
        status = line_info.split(" ")
        removeEmpty(status)
        status1 = status[1].strip()
        if status1 != "Approved"
        goto .start
    elif line_info.find('BuildDate') == 0:
        # Main Make
        print "  Found BuildDate"
        logString += "  Found BuildDate\n"
        builddate1 = line_info.split(" ")
        removeEmpty(builddate1)
        builddate1 = builddate1[1]
        #if builddate1 > 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:16:43+00:00Added an answer on June 13, 2026 at 6:16 pm

    Try this code:

    lastLocation = None
    lastTime = None
    skip = False
    
    bestLocation = None
    bestTime = None
    
    for line in text.split('\n'):    
        line.find('Location')
        if line.find('Location') == 0:
            # Build Location
            skip = False
            print "  Found Build location"
            lastLocation = line.split(":")[1].lstrip()       
        elif line.find('Status') == 0:
            # Status
            print "  Found Status"
            status = line.split(":")
            status1 = status[1].strip()
            if status1 != "Approved":
                skip = True
        elif line.find('BuildDate') == 0 and not skip:
            # Main Make
            print "  Found BuildDate"
            timeStr = line.split(":", 1)[1].lstrip()
            lastTime = datetime.datetime.strptime(timeStr, "%m/%d/%Y %H:%M:%S")
            if bestTime == None or bestTime < lastTime:
                bestTime = lastTime
                bestLocation = lastLocation
    print lastLocation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have maven-plagin and need to run goal, that should automatically run before plugin.
I have a multi-page PDF file that has information I need to parse. The
I need to parse a configuration file which looks like this (simplified): <config> <links>
I need an input file stream which would have a bidirectional iterator/adapter. Unfortunately std::ifstream
I need to parse an UTF-8 encoded input stream, so I think the most
I need to parse a .txt file to three double arrays. This files has
Goal I need to alter a number of almost identical triggers on a number
Goal: Gain datatype date with year and month Problem: Need to help to convert
Core Question I need help coming up with a concept to achieve my goal.
My end goal is local development of a Radiant CMS installation. So, need rails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.