topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday April 18, 2024, 6:37 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: add / remove lines in text file  (Read 9759 times)

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
add / remove lines in text file
« on: September 21, 2007, 05:57 AM »
I'm looking for a small coding snack which i think should be easy for someone who has done something similar:
I want it to open a configuration file,
add one or more series of lines over time
and being able to work with these lines even though another program might have changed the same file at another point in time.
Addittionaly if the program would be able to add the same operations to a file on another computer (so i can take it home on a usb stick and save more time) that would be a bonus.
This means the program has to detect its own additions, but can't rely on looking at the top or bottom of the file.

I need this to setup dozens of development websites. Each of them needs a line in the HOSTS file. However other software adds lines to this file (for example anti-spyware tools). Fortunately HOSTS supports commenting by prefixing a line with #

If I could take my hosts-file-changes home and add them there too that would be ace. Then I can make changes whereever i like and add them to the other side with a few clicks.


JennyB

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 212
  • Test all things - hold fast to what is good
    • View Profile
    • Donate to Member
Re: add / remove lines in text file
« Reply #1 on: September 22, 2007, 12:48 PM »
Would this work?

    Change file1 file2

Apply the changes in file1 to file2

File1 is a text file with the format:

   > Line to search from or insert after (default is bof)
   < Line to stop searching at
   + Line to add
   - Delete any lines starting with this text

If you don't see how it can fail -
you haven't understood it properly.

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: add / remove lines in text file
« Reply #2 on: September 22, 2007, 01:33 PM »
yeah you're thinking about patching aret you :)

tanatos

  • Participant
  • Joined in 2006
  • *
  • Posts: 4
    • View Profile
    • Donate to Member
Re: add / remove lines in text file
« Reply #3 on: January 22, 2008, 01:26 PM »
i might be able to help you out if you would like...