If I were to write a scripts where I wanted to open my httpd.conf file and add a virtual tag, how do I tell it to write any where but the eof? Also not by line number.
The only way to do an in-place edit is to change bytes in the file on a one-for-one basis. One option is to work it like perl's -i cli switch and move the old file to a new filename (httpd.conf.bak), then open the old/original filename (httpd.conf) as a new file. Open the backup for reading and print line-by-line into the new file until you get to the point you want to insert text, insert, and continue to append the backup file. Delete the backup when the script finishes.
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
Another option is to search and replace for the spot where you want to put the tag in using regular expressions. This of course only works if you a spot to search for..
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.