ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Coding Snacks

add / remove lines in text file


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.

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

yeah you're thinking about patching aret you :)

i might be able to help you out if you would like...


[0] Message Index

Go to full version