<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: C# Search/Replace in Files</title>
	<atom:link href="http://www.csharp411.com/searchreplace-in-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.csharp411.com/searchreplace-in-files/</link>
	<description>C# Information, Code, Tips and News</description>
	<lastBuildDate>Sat, 24 Jul 2010 01:26:51 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: RandiR</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-5387</link>
		<dc:creator>RandiR</dc:creator>
		<pubDate>Wed, 17 Feb 2010 15:03:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-5387</guid>
		<description>Nice article.

I thought I share this - it will probably be good complementary information for the article.

When I need to do a quick and dirty search and replace, I use biterscripting. Here are some sample scripts.


- Script to replace &quot;ABC&quot; with &quot;XYZ&quot; in file X.txt.

var str content
cat &quot;X.txt&quot; &gt; $content
sal &quot;^ABC^&quot; &quot;XYZ&quot; $content &gt; null
echo $content &gt; &quot;X.txt&quot;



- Script to perform many replace operations on the same file X.txt. (I create a file C:/ReplaceList.txt in which the first field is ABC, the second field is XYZ. The fields are separated by tabs. One replace entry per line.)

var str content, searchstr, replacestr, entry, entrylist
set $wsep=&quot;\t&quot;
cat &quot;X.txt&quot; &gt; $content
cat &quot;C:/ReplaceList.txt&quot; &gt; $entrylist
lex &quot;1&quot; $entrylist &gt; $entry
while ($entry  &quot;&quot;)
do
    wex -p &quot;1&quot; $entry &gt; searchstr
    wex -p &quot;2&quot; $entry &gt; replacestr
    sal (&quot;^&quot;+$searchstr+&quot;^&quot;) $replacestr $content &gt; null
    lex &quot;1&quot; $entrylist &gt; $entry
done
echo $content &gt; &quot;X.txt&quot;



- Script to perform many replace operations on every .txt file in folder C:/folder. (The same C:/ReplaceList.txt file is used to specify what to replace with what.)

var str content, searchstr, replacestr, entry, entrylist, filelist, file
set $wsep=&quot;\t&quot;
lf -n &quot;*.txt&quot; &quot;C:/folder&quot; &gt; $filelist
while ($filelist  &quot;&quot;)
do
    lex &quot;1&quot; $filelist &gt; $file
    cat $file &gt; $content
    cat &quot;C:/ReplaceList.txt&quot; &gt; $entrylist
    lex &quot;1&quot; $entrylist &gt; $entry
    while ($entry  &quot;&quot;)
    do
        wex -p &quot;1&quot; $entry &gt; searchstr
        wex -p &quot;2&quot; $entry &gt; replacestr
        sal (&quot;^&quot;+$searchstr+&quot;^&quot;) $replacestr $content &gt; null
        lex &quot;1&quot; $entrylist &gt; $entry
    done
    echo $content &gt; { echo $file }
done



The command we are using is sal (string alterer). Its help page is at http://www.biterscripting.com/helppages/sal.html. One can also use regular expressions with this command.</description>
		<content:encoded><![CDATA[<p>Nice article.</p>
<p>I thought I share this &#8211; it will probably be good complementary information for the article.</p>
<p>When I need to do a quick and dirty search and replace, I use biterscripting. Here are some sample scripts.</p>
<p>- Script to replace "ABC" with "XYZ" in file X.txt.</p>
<p>var str content<br />
cat "X.txt" &gt; $content<br />
sal "^ABC^" "XYZ" $content &gt; null<br />
echo $content &gt; "X.txt"</p>
<p>- Script to perform many replace operations on the same file X.txt. (I create a file C:/ReplaceList.txt in which the first field is ABC, the second field is XYZ. The fields are separated by tabs. One replace entry per line.)</p>
<p>var str content, searchstr, replacestr, entry, entrylist<br />
set $wsep="\t"<br />
cat "X.txt" &gt; $content<br />
cat "C:/ReplaceList.txt" &gt; $entrylist<br />
lex "1&#8243; $entrylist &gt; $entry<br />
while ($entry  "")<br />
do<br />
    wex -p "1&#8243; $entry &gt; searchstr<br />
    wex -p "2&#8243; $entry &gt; replacestr<br />
    sal ("^"+$searchstr+"^") $replacestr $content &gt; null<br />
    lex "1&#8243; $entrylist &gt; $entry<br />
done<br />
echo $content &gt; "X.txt"</p>
<p>- Script to perform many replace operations on every .txt file in folder C:/folder. (The same C:/ReplaceList.txt file is used to specify what to replace with what.)</p>
<p>var str content, searchstr, replacestr, entry, entrylist, filelist, file<br />
set $wsep="\t"<br />
lf -n "*.txt" "C:/folder" &gt; $filelist<br />
while ($filelist  "")<br />
do<br />
    lex "1&#8243; $filelist &gt; $file<br />
    cat $file &gt; $content<br />
    cat "C:/ReplaceList.txt" &gt; $entrylist<br />
    lex "1&#8243; $entrylist &gt; $entry<br />
    while ($entry  "")<br />
    do<br />
        wex -p "1&#8243; $entry &gt; searchstr<br />
        wex -p "2&#8243; $entry &gt; replacestr<br />
        sal ("^"+$searchstr+"^") $replacestr $content &gt; null<br />
        lex "1&#8243; $entrylist &gt; $entry<br />
    done<br />
    echo $content &gt; { echo $file }<br />
done</p>
<p>The command we are using is sal (string alterer). Its help page is at <a href="http://www.biterscripting.com/helppages/sal.html" rel="nofollow">http://www.biterscripting.com/helppages/sal.html</a>. One can also use regular expressions with this command.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: QA WA</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-5361</link>
		<dc:creator>QA WA</dc:creator>
		<pubDate>Tue, 12 Jan 2010 00:11:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-5361</guid>
		<description>I&#039;m unable to make this code snippett work.  I tries the ,param and that failed. I changed that to adding values to string variables, that did not work ( see attached code)  Any help would begreatly appreciated.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace FindReplaceLogLevel
{
   public class Program

    {
       public void Main(string[] args)
       {

           string filePath = (@&quot;C:\goat\goattest&quot;); 
           string searchText = (&quot;goat&quot;); 
           string replaceText = (&quot;mutton&quot;);
       }
            
                    static public void ReplaceInFile(string filePath,string searchText,string replaceText)
                    {
                    StreamReader reader = new StreamReader(filePath);
                    string content = reader.ReadToEnd();
                    reader.Close();

                    content = Regex.Replace( content, searchText, replaceText );

                    StreamWriter writer = new StreamWriter( filePath );
                    writer.Write( content );
                    writer.Close();
                    }


                 
    }
}</description>
		<content:encoded><![CDATA[<p>I'm unable to make this code snippett work.  I tries the ,param and that failed. I changed that to adding values to string variables, that did not work ( see attached code)  Any help would begreatly appreciated.<br />
using System;<br />
using System.Collections.Generic;<br />
using System.IO;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Text.RegularExpressions;</p>
<p>namespace FindReplaceLogLevel<br />
{<br />
   public class Program</p>
<p>    {<br />
       public void Main(string[] args)<br />
       {</p>
<p>           string filePath = (@"C:\goat\goattest");<br />
           string searchText = ("goat");<br />
           string replaceText = ("mutton");<br />
       }</p>
<p>                    static public void ReplaceInFile(string filePath,string searchText,string replaceText)<br />
                    {<br />
                    StreamReader reader = new StreamReader(filePath);<br />
                    string content = reader.ReadToEnd();<br />
                    reader.Close();</p>
<p>                    content = Regex.Replace( content, searchText, replaceText );</p>
<p>                    StreamWriter writer = new StreamWriter( filePath );<br />
                    writer.Write( content );<br />
                    writer.Close();<br />
                    }</p>
<p>    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: QAguy</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-5354</link>
		<dc:creator>QAguy</dc:creator>
		<pubDate>Tue, 05 Jan 2010 03:45:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-5354</guid>
		<description>The snippett did not work for me.  I received invalid token errors when I attempted to add a path to the paramater definition.
I&#039;m a noob so I know I&#039;m missing something.</description>
		<content:encoded><![CDATA[<p>The snippett did not work for me.  I received invalid token errors when I attempted to add a path to the paramater definition.<br />
I'm a noob so I know I'm missing something.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Troy</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-5344</link>
		<dc:creator>Troy</dc:creator>
		<pubDate>Wed, 16 Dec 2009 19:15:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-5344</guid>
		<description>Very helpful.  Thank you very much!</description>
		<content:encoded><![CDATA[<p>Very helpful.  Thank you very much!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-5296</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 01 Oct 2009 16:01:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-5296</guid>
		<description>Nice easy search and replace!</description>
		<content:encoded><![CDATA[<p>Nice easy search and replace!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dos santos</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-5278</link>
		<dc:creator>dos santos</dc:creator>
		<pubDate>Fri, 11 Sep 2009 08:04:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-5278</guid>
		<description>Thanks, very easy way to solve the hard job I was planning...</description>
		<content:encoded><![CDATA[<p>Thanks, very easy way to solve the hard job I was planning&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timm</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-4999</link>
		<dc:creator>timm</dc:creator>
		<pubDate>Mon, 01 Jun 2009 14:57:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-4999</guid>
		<description>Here&#039;s some good code on this subject:

http://towardsnext.wordpress.com/2009/02/02/replace-data-in-file-c/</description>
		<content:encoded><![CDATA[<p>Here's some good code on this subject:</p>
<p><a href="http://towardsnext.wordpress.com/2009/02/02/replace-data-in-file-c/" rel="nofollow">http://towardsnext.wordpress.com/2009/02/02/replace-data-in-file-c/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-4533</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Fri, 10 Apr 2009 16:03:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-4533</guid>
		<description>Hi timm, I have just send an email to the emailaddress you provided.

Hope to be hearing from you.</description>
		<content:encoded><![CDATA[<p>Hi timm, I have just send an email to the emailaddress you provided.</p>
<p>Hope to be hearing from you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: timm</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-4532</link>
		<dc:creator>timm</dc:creator>
		<pubDate>Fri, 10 Apr 2009 13:34:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-4532</guid>
		<description>Hi Kevin, you can post the code in a comment here, but the WordPress comment formatting is poor, everything gets left-adjusted.  

A better solution, if you are interested, is you can send me the code, and I can publish an article with it, of course giving you full credit.  It would be a great service to our readers.

You can contact us at &quot;info at tiwebb dot com&quot;

Thank you!</description>
		<content:encoded><![CDATA[<p>Hi Kevin, you can post the code in a comment here, but the WordPress comment formatting is poor, everything gets left-adjusted.  </p>
<p>A better solution, if you are interested, is you can send me the code, and I can publish an article with it, of course giving you full credit.  It would be a great service to our readers.</p>
<p>You can contact us at "info at tiwebb dot com"</p>
<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.csharp411.com/searchreplace-in-files/comment-page-1/#comment-4531</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Fri, 10 Apr 2009 12:04:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.mini-tools.com/at2/csharp/wordpress/searchreplace-in-files/#comment-4531</guid>
		<description>I have also been dealing with the problem of too large files to completly read into the memory. Now I have created a method that will replace occurences in a text file without dealing with memory issues. How can I post the code to this website so that you can benefit from it? I can&#039;t see a place to aquire membership to C# 411. This is also my first comment on this site...</description>
		<content:encoded><![CDATA[<p>I have also been dealing with the problem of too large files to completly read into the memory. Now I have created a method that will replace occurences in a text file without dealing with memory issues. How can I post the code to this website so that you can benefit from it? I can't see a place to aquire membership to C# 411. This is also my first comment on this site&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
