tags:

views:

218

answers:

1

I would like to know if anyone can help me with this. I would like to search a text file for a certain line of text, add a new line under the specific line then add text to the new line. I will be using this to edit the firefox.js file to add the line of text to add support for Iprism. It will run on XP and Windows 7 machines.

I would like to have a batch file that will open firefox.js find the line "pref("browser.xul.error_pages.expert_bad_cert", false);" add a new line uder it and add pref("network.automatic-ntlm-auth.trusted-uris", "IP of Iprsim");

Edited for better explanation!!

Any help would be very appreciated!!!

Damian

+1  A: 

You can iterate over lines in a file with for /f. You need to keep track of the line you're currently at, compare it to what you look for and in case you found the line you were looking for do something. This something looks roughly as follows: You output each line you process to stdout or a new file directly and when you find your desired line you do exactly the same but write something else to that new file as well. At the very end you simply delete your old input file and rename the new one.

In a batch file this might look somehow like the following (untested, so careful):

for /f %%x in (inputfile) do (
    echo %%x>>newfile
    if ("%%x"=="Ex3") (
        echo Ex4>>newfile
    )
)

del inputfile
ren newfile inputfile

Of course, adapt as you see fit.

Joey