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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:01:54+00:00 2026-06-10T22:01:54+00:00

I apologize if this post is long, but I am trying to be as

  • 0

I apologize if this post is long, but I am trying to be as detailed as possible. I have done a considerable amount of research on the topic, and would consider myself an “intermediate” skilled programmer.

My problem: I have a text file with multiple lines of data. I would like to remove certain parts of each line in an effort to get rid of some irrelevant information, and then save the file with the newly formatted lines.

Here is an example of what I am trying to accomplish. The original line is something like:

access-list inbound_outside1 line 165 extended permit tcp any host 209.143.156.200 eq www (hitcnt=10086645) 0x3eb90594

I am trying to have the code read the text file, and output:

permit tcp any 209.143.156.200 www 

The following code works, but only if there is a single line in the text file:

input_file = open("ConfigInput.txt", "r")
output_file = open("ConfigOutput.txt", "w")

for line in input_file:
    line = line.split("extended ", 1)[1]
    line = line.split("(", 1)[0]
    line = line.replace(" host", "")
    line = line.replace(" eq", "")
    output_file.write(line)

output_file.close()
input_file.close()

However, when I attempt to run this with a full file of multiple lines of data, I receive an error:

File "C:\Python27\asaReader", line 5, in <module>
    line = line.split("extended ", 1)[1]
IndexError: list index out of range

I suspect that it is not moving onto the next line of data in the text file, and therefore there isn’t anything in [1] of the previous string. I would appreciate any help I can get on this.

  • 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-10T22:01:56+00:00Added an answer on June 10, 2026 at 10:01 pm

    Some possible causes:

    • You have blank lines in your file (blank lines obviously won’t contain the word extended)
    • You have lines that aren’t blank, but don’t contain the word extended

    You could try printing your lines individually to see where the problem occurs:

    for line in input_file:
        print("Got line: %s" % (line))
        line = line.split("extended ", 1)[1]
    

    Oh, and it’s possible that the last line is blank and it’s failing on that. It would be easy enough to miss.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize for the long post, but this problem is not easily stated. I
Apologize if this is too long of a post. I'm merely trying to get
Apologies for the rather verbose and long-winded post, but this problem's been perplexing me
Apologies for the long post -- Read a few threads about this, but still
I do apologize if this post is a duplicate, but I haven't found anything
I will apologize in advance as this post is born out of severe frustration.
First of all, I would like to apologize for posting this again. I am
Please bear with me, my apologies if this post is too long... I'm attempting
Apologies for the long post, I have tried to provide you with as much
Okay well I apologize for how sloppy this code is, but I still cant

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.