Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use GNU Win32 <a href="http://gnuwin32.sourceforge.net/packages/sed.htm" rel="nofollow">sed</a> for this: </p> <pre class="lang-none prettyprint-override"><code>for /r "MyApp/Views" %%a in (*.cshtml) do sed -ibak "s#http://localhost\.com#http://domain.com#g" "%%~a" </code></pre> <p>The <code>for /r</code> loop searches all folders recursively and <code>sed</code> changes the URL's in all <code>*.cshtml</code> files. It also makes a backup copy <code>*.bak</code>.</p> <hr> <p>Batch is much lesser safe, but if you want- here is my suggestion in batch:</p> <pre class="lang-none prettyprint-override"><code>@echo OFF &amp;SETLOCAL SET "fpath=MyApp\Views" SET "newext=.new" SET "fname=" for /r "%fpath%" %%a in (*.cshtml) DO SET "fname=%%~a"&amp;CALL:process goto:eof :process (FOR /f "delims=" %%b IN ('findstr /n "^" "%fname%"') DO ( SET "line=%%b" SETLOCAL ENABLEDELAYEDEXPANSION SET "line=!line:*:=!" IF "!line:http://localhost.com=!" neq "!line!" ( SET "line=!line:http://localhost.com=http://domain.com!" ) ECHO(!line! ENDLOCAL ))&gt;"%fname%%newext%" goto:eof </code></pre> <p>How it works:</p> <ul> <li>the first <code>for</code> loop: read the directory of the startfolder recursively, put the file names successively in a variable and call a sub routine <code>process</code> for each file.</li> <li>the second <code>for</code> loop: read the file line by line with the use of <code>findstr</code> to preserve empty lines. Replace all <code>http://localhost.com</code> to <code>http://domain.com</code> if it appears and write the lines to a new file.</li> </ul> <p>Used variables:</p> <ul> <li><code>%fpath%</code> path to files to process, default <code>MyApp\Views</code></li> <li><code>%newext%</code> extension for the new file, default <code>.new</code></li> </ul> <p>Benefits:</p> <ul> <li>preserve empty lines with <code>findstr</code></li> <li>preserve exclamation marks by toggeling <code>delayed expansion</code> in the second <code>for</code> loop</li> <li>preserve percent signs <code>%</code> in file names by use of a global variable</li> </ul> <p>Issues:</p> <ul> <li>Windows Command Shell Language (<em>WCSL</em>, aka 'batch') can not treat lines longer than <strong>8191</strong> characters, not so much for HTML content</li> <li>well, batch is not a racing car and dependent of the amount of your content this can be an veritable overnight job</li> </ul> <p><sub><em>Good luck!</em></sub></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload