1

I need to remove the following line:

user_pref("network.proxy.http", "177.22.10.226");

located in the file:

%APPDATA%\Mozilla\Firefox\Profiles\zizwksvf.default\prefs.js

and replace it with the following line:

user_pref("network.proxy.http", "177.22.10.116");

i.e. basically I have to replace the address of the proxy using command lines within batch files. Since I dont know beforehand which is the line I have to replace(can be any IP) I wanna use * to replace all lines having the string "network.proxy.http" including quotes like this:

fart %APPDATA%\Mozilla\Firefox\Profiles\zizwksvf.default\prefs.js """*network.proxy.http*""" "user_pref("network.proxy.http", "177.22.10.116");"

but it does not work, no elemnts are found, while if I try have a previow of how many elements would be sostitute by using:

fart -p %APPDATA%\Mozilla\Firefox\Profiles\zizwksvf.default\prefs.js """network.proxy.http"""

it says it finds one element. Any suggestion?

Cheers A.

Millemila
  • 1,612
  • 4
  • 24
  • 45
  • 1
    The title* made me lol – FirebladeDan Jul 31 '15 at 18:03
  • @FirebladeDan That's because you yet have to experience the powers of the [Find And Replace Tool](http://fart-it.sourceforge.net/). :) – GolezTrol Jul 31 '15 at 18:08
  • As for the problem. You say with `-p` it finds a match, but that line is different from the other. `"""network.proxy.http"""` vs `"""*network.proxy.http*"""` (asterisks). So probably there in lies the problem? – GolezTrol Jul 31 '15 at 18:09
  • 1
    Is it just me, or do the lines you want to find and replace look identical? – abelenky Jul 31 '15 at 19:43
  • Ok i just changed the IP, it is clear I have to change the IP every time. The asterisks should match any letter in the front and in the back if regex works. – Millemila Aug 01 '15 at 16:06

2 Answers2

4

Would recommend you to not use anything hosted on sourceforge . You can do that without any pre-compiled binaries. You can try replacer.bat (the e? before the file name is for evaluation of unicode sequences - quotes in this case )

call replacer.bat "e?%APPDATA%\Mozilla\Firefox\Profiles\zizwksvf.default\prefs.js" "user_pref(\u0022network.proxy.http\u0022, \u0022177.22.10.116\u0022);" "user_pref(\u0022network.proxy.http\u0022, \u0022177.22.10.116\u0022);"

you can check also FindRepl and JRepl which are more sophisticated tools

EDIT.According to the help page you can use -C option and use \x22 instead of double quotes in your arguments.

wimh
  • 15,072
  • 6
  • 47
  • 98
npocmaka
  • 55,367
  • 18
  • 148
  • 187
1

There are several different ways to do that with Batch files, from the advanced tools that npocmaka suggested to simpler one-purpose Batch files; like this one:

@echo off
setlocal EnableDelayedExpansion

set "find=network.proxy.http"
set "repl=user_pref("network.proxy.http", "177.22.10.116");"

rem Get the line number of the search line
for /F "delims=:" %%a in ('findstr /N /C:"%find%" input.txt') do set /A "numLines=%%a-1"

rem Open a code block to read-input-file/create-output-file

< input.txt (

   rem Copy numLines-1 lines
   set /P line=
   for /L %%i in (1,1,%numLines%) do (
      echo(!line!
      set "line="
      set /P "line="
   )

   rem Replace the search line
   echo %repl%

   rem Copy the rest of lines
   findstr "^"

) > output.txt

rem Replace input file with created output file
move /Y output.txt input.txt > NUL

This Batch file is a modification of the one posted at this answer.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108