This discussion is archived
4 Replies Latest reply: Aug 26, 2008 5:58 AM by 843785 RSS

Replacing pieces of a String from a configuration

843785 Newbie
Currently Being Moderated
Hello -
I have been asked to write a program that will take a router/switch configuration and replace all instances of a password key and replace it with REMOVED so when we need to send the configurations out, it's simple to get rid of the passwords. The issue I am having is how to replace them. The only way they are flagged is by having something in front of, ie enable secret 5, then the key follows. I have written a program to input the config line by line and then I though to create a new tokenizer for each line, however I am not sure how to replace the data since I cannot search the string on certain data to replace, I can just search no the data before the key. I have not been able to find something that will work to replace the data after the keywords I search on. Also my tokenizer doesn't seem to be breaking the line up in tokens by whitespace. Any ideas would be greatly appreciated!!
  • 1. Re: Replacing pieces of a String from a configuration
    800308 Newbie
    Currently Being Moderated
    You're talking about a standard property file, in the format:
    [path.to.]name=value
    Aren't you?
  • 2. Re: Replacing pieces of a String from a configuration
    843785 Newbie
    Currently Being Moderated
    Actually I had never even hear of a standard property file. I was actually just using a .txt file. Would the standard file be easier to work with? I just looked it up, but I didn't see how to convert a file to be a standard property file??
  • 3. Re: Replacing pieces of a String from a configuration
    800308 Newbie
    Currently Being Moderated
    Have a look at the [Properties API Doco|http://java.sun.com/javase/6/docs/api/java/util/Properties.html], you decide it it's useful.

    "Just a text file" gives us zero idea of the format... you're going to need to be much more forthcoming with the nitty gritty in order to recieve any real help here... While can read minds, we try to refrain from doing so, as we've discovered that is seriously upsets the management.

    Edited by: corlettk on 26/08/2008 22:41 - Ooops!
  • 4. Re: Replacing pieces of a String from a configuration
    843785 Newbie
    Currently Being Moderated
    Here is an example of what the .txt file looks like, and it is in notepad:

    Current configuration : 24336 bytes
    !
    !
    version 12.4
    service nagle
    no service pad
    service timestamps debug datetime localtime
    service timestamps log datetime localtime
    service password-encryption
    !
    hostname hostname
    !
    boot-start-marker
    !
    card ype
    logging buffered
    no logging console
    enable secret 5 **%3920$1rizoekw/lvslhe$** - what I need to replace
    !
    aaa new-model


    And it goes on and on. So what I had so far was to actually open the file, bring it in line by line and search each line for the phrases to look for, which works but I just don't know how to replace the text after the phrase, such as the info after the 5 in the example above.