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 8166255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:47:49+00:00 2026-06-06T19:47:49+00:00

I am writing a python command line script that takes a .ldif and two

  • 0

I am writing a python command line script that takes a .ldif and two strings. The strings correspond to a key and a value that I need to insert at the end of each record in the .ldif file. However, I’m having an issue figuring out how to parse the .ldif file so that I know I’m at the end of a record. When I reach the end of a record I need to write to the file the two strings (Key: Value) with a colon in between them.

So basically I need to:

  1. Parse arguments from the command line (.ldif, string1, string2)
  2. Create the string I am going to append to the .ldif
  3. Open the .ldif and seek to the end of each record. Upon reaching the end of a record I need to write the string I created from string1 and string2.
  4. When I see the EOF of the .ldif I need to return the .ldif file with the updated records.

Before:


    # example.ldif
    dn: Aamir_005_000
    cn: Aamir_25
    givenname: Aamir

    dn: Saul_024
    cn: Saululite
    givenname: Saul

After: python myscript.py ./example.ldif sillyname syllabear


    # example.ldif
    dn: Aamir_005_000
    cn: Aamir_25
    givenname: Aamir
    sillyname: syllabear

    dn: Saul_024
    cn: Saululite
    givenname: Saul
    sillyname: syllabear

  • 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-06T19:47:51+00:00Added an answer on June 6, 2026 at 7:47 pm
    import sys
    with open(sys.argv[1],'r+') as f1:
        lines=[x.strip() for x in f1]
        f1.truncate(0)
        f1.seek(0)
        for x in lines:
           if x:
             f1.write(x+'\n')
           else:
             f1.write("{0}:{1}\n\n".format(sys.argv[2],sys.argv[3]))
        f1.write("{0}:{1}\n\n".format(sys.argv[2],sys.argv[3])) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to python. I'm writing a script that calls a command line tool
I'm writing a program in Python that accepts command line arguments. I am parsing
I have a completely non-interactive python program that takes some command-line options and input
I'm writing a script to automate some command line commands in Python. At the
Hey guys/gals I'm writing a python script that fixes some duplicate issues on my
I'm currently writing a Python GDB script. The problem is that it has to
Im new to python programming.Im writing a simple command line based twitter app,and i
I'm writing a python script that calls another python script (script2). I want to
I'm writing some code (Python, but really isn't important) that analyzes strings inside PE
In a bit of Python I'm writing (a command line and filter testing tool:

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.