<?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: Howto Replace multiple file text string in Linux</title>
	<atom:link href="http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html</link>
	<description>Debian/Ubuntu Linux System Administration Tutorials,Howtos,Tips</description>
	<lastBuildDate>Mon, 06 Feb 2012 02:01:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Rob Groen</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-9431</link>
		<dc:creator>Rob Groen</dc:creator>
		<pubDate>Tue, 31 Jan 2012 11:33:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-9431</guid>
		<description>just place a g (global) behind the last slash in 

grep -l OLDTEXT * &#124; xargs perl -pi~ -e ‘s/OLDTEXT/NEWTEXT/’

so it becomes

grep -l OLDTEXT * &#124; xargs perl -pi~ -e ‘s/OLDTEXT/NEWTEXT/g’</description>
		<content:encoded><![CDATA[<p>just place a g (global) behind the last slash in </p>
<p>grep -l OLDTEXT * | xargs perl -pi~ -e ‘s/OLDTEXT/NEWTEXT/’</p>
<p>so it becomes</p>
<p>grep -l OLDTEXT * | xargs perl -pi~ -e ‘s/OLDTEXT/NEWTEXT/g’</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lena Schimmel</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-9388</link>
		<dc:creator>Lena Schimmel</dc:creator>
		<pubDate>Fri, 27 Jan 2012 13:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-9388</guid>
		<description>Attention! None of the above commands (neither perl nor sed) seem to work correctly if OLDSTRING is found multiple times within the same line. In this case, only the first occurence within that line will be replaced and others remain unchanged. (Tested with perl 5.10.1 with debian patches and GNU sed 4.2.1)

Is there a way to fix that? (For me it&#039;s not a real problem, so I won&#039;t come back here to check your answers, but maybe this well help someone else who stumbles across this page...)</description>
		<content:encoded><![CDATA[<p>Attention! None of the above commands (neither perl nor sed) seem to work correctly if OLDSTRING is found multiple times within the same line. In this case, only the first occurence within that line will be replaced and others remain unchanged. (Tested with perl 5.10.1 with debian patches and GNU sed 4.2.1)</p>
<p>Is there a way to fix that? (For me it&#8217;s not a real problem, so I won&#8217;t come back here to check your answers, but maybe this well help someone else who stumbles across this page&#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karth</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-5722</link>
		<dc:creator>Karth</dc:creator>
		<pubDate>Mon, 30 Aug 2010 06:21:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-5722</guid>
		<description>Hello,
 I need to search and replace multiple words in one pass of an input
stream or string. For example, given the input:

&quot;The quick brown fox jumped over the lazy dog&#039;s back&quot;

and given the replacements

quick -&gt; slow
jump -&gt; walk

I&#039;d like to get the string

&quot;The slow brown fox walked over the lazy dog&#039;s back.&quot;
Which perl command do i use?(i used foreach but it is printing lines multiple times)..
If you need i will produce code..

thanks
karth</description>
		<content:encoded><![CDATA[<p>Hello,<br />
 I need to search and replace multiple words in one pass of an input<br />
stream or string. For example, given the input:</p>
<p>&#8220;The quick brown fox jumped over the lazy dog&#8217;s back&#8221;</p>
<p>and given the replacements</p>
<p>quick -&gt; slow<br />
jump -&gt; walk</p>
<p>I&#8217;d like to get the string</p>
<p>&#8220;The slow brown fox walked over the lazy dog&#8217;s back.&#8221;<br />
Which perl command do i use?(i used foreach but it is printing lines multiple times)..<br />
If you need i will produce code..</p>
<p>thanks<br />
karth</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-4573</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Sun, 07 Mar 2010 14:01:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-4573</guid>
		<description>I found this page via Google as I couldn&#039;t remember how to do it.  

I&#039;m using Centos 5 32bit though, putting in grep -Rl (then the rest of it) as mentioned gave me the error &#039;Argument too long&#039;.

I had to replace the . with * as it&#039;d just sit there doing nothing, anyway I found the following to work best for me, but it&#039;s non recursive...

grep -l OLDTEXT * &#124; xargs perl -pi~ -e &#039;s/OLDTEXT/NEWTEXT/&#039;</description>
		<content:encoded><![CDATA[<p>I found this page via Google as I couldn&#8217;t remember how to do it.  </p>
<p>I&#8217;m using Centos 5 32bit though, putting in grep -Rl (then the rest of it) as mentioned gave me the error &#8216;Argument too long&#8217;.</p>
<p>I had to replace the . with * as it&#8217;d just sit there doing nothing, anyway I found the following to work best for me, but it&#8217;s non recursive&#8230;</p>
<p>grep -l OLDTEXT * | xargs perl -pi~ -e &#8216;s/OLDTEXT/NEWTEXT/&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: david</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-4402</link>
		<dc:creator>david</dc:creator>
		<pubDate>Tue, 09 Feb 2010 07:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-4402</guid>
		<description>I want to search for start and end of some words and then replace them with : ..how do I make 
&#039;OLDSTRING&#039; a search expression ? Can I do that..
if not how do I search this and replace based on an expression ..</description>
		<content:encoded><![CDATA[<p>I want to search for start and end of some words and then replace them with : ..how do I make<br />
&#8216;OLDSTRING&#8217; a search expression ? Can I do that..<br />
if not how do I search this and replace based on an expression ..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-4027</link>
		<dc:creator>J</dc:creator>
		<pubDate>Wed, 18 Nov 2009 17:22:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-4027</guid>
		<description>James&#039; solutions don&#039;t work if your directories have space in their names.</description>
		<content:encoded><![CDATA[<p>James&#8217; solutions don&#8217;t work if your directories have space in their names.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afjal</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-3454</link>
		<dc:creator>afjal</dc:creator>
		<pubDate>Thu, 30 Jul 2009 20:46:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-3454</guid>
		<description>1. $grep -R –files-with-matches ‘OLDSTRING’ . &#124; sort &#124; uniq &#124; xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’


2. $ grep -rl OLDSTRING . &#124; xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’


I tried both the options, but no use, i am on Linux4 63 bit.

please let me know how to proceed !

Thanks to ALL</description>
		<content:encoded><![CDATA[<p>1. $grep -R –files-with-matches ‘OLDSTRING’ . | sort | uniq | xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’</p>
<p>2. $ grep -rl OLDSTRING . | xargs perl -pi~ -e ’s/OLDSTRING/NEWSTRING/’</p>
<p>I tried both the options, but no use, i am on Linux4 63 bit.</p>
<p>please let me know how to proceed !</p>
<p>Thanks to ALL</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eol</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-1842</link>
		<dc:creator>Eol</dc:creator>
		<pubDate>Tue, 12 Aug 2008 23:57:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-1842</guid>
		<description>James&#039;s solution works excellent for me
Thanks a lot!</description>
		<content:encoded><![CDATA[<p>James&#8217;s solution works excellent for me<br />
Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-1841</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sat, 01 Sep 2007 22:56:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-1841</guid>
		<description>daniel:

You&#039;ll get that error if you copy and paste the line from your web browser because the single quote character that is pasted isn&#039;t the same that you would type.  Just delete the &#039;s from the command and type them back in manually.  Also, it appears that you might have an extra &#039; just before the //&#039; at the end of your command.

I used James&#039; version, retyping the single quotes, and it ran perfectly, thanks!</description>
		<content:encoded><![CDATA[<p>daniel:</p>
<p>You&#8217;ll get that error if you copy and paste the line from your web browser because the single quote character that is pasted isn&#8217;t the same that you would type.  Just delete the &#8216;s from the command and type them back in manually.  Also, it appears that you might have an extra &#8216; just before the //&#8217; at the end of your command.</p>
<p>I used James&#8217; version, retyping the single quotes, and it ran perfectly, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daniel</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-1840</link>
		<dc:creator>daniel</dc:creator>
		<pubDate>Wed, 29 Aug 2007 19:17:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-1840</guid>
		<description>In 1600 files want to replace the strings &quot;text: &quot; by nothing, so i give the command

$ grep -R -l &#039;text: &#039; . &#124; sort &#124; uniq &#124; xargs perl -pi~ -e &#039;s/text: &#039;//’

and then Ubuntu Feisty says
Unrecognized character \xE2 at -e line 1.
xargs: perl: exited with status 255; aborting

how to proceed?</description>
		<content:encoded><![CDATA[<p>In 1600 files want to replace the strings &#8220;text: &#8221; by nothing, so i give the command</p>
<p>$ grep -R -l &#8216;text: &#8216; . | sort | uniq | xargs perl -pi~ -e &#8216;s/text: &#8216;//’</p>
<p>and then Ubuntu Feisty says<br />
Unrecognized character \xE2 at -e line 1.<br />
xargs: perl: exited with status 255; aborting</p>
<p>how to proceed?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html/comment-page-1#comment-1839</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 13 Aug 2007 14:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.debianadmin.com/howto-replace-multiple-file-text-string-in-linux.html#comment-1839</guid>
		<description>Not sure why you run uniq on it, grep is perfectly capable of only returning unique results... And use the short options please. This should do just fine:

$ grep -rl OLDSTRING . &#124; xargs perl -pi~ -e &#039;s/OLDSTRING/NEWSTRING/&#039;

and if you want to do it sorted, files (this will even do unique results too!):

$ grep -rl OLDSTRING . &#124; sort -u &#124; xargs perl -pi~ -e &#039;s/OLDSTRING/NEWSTRING/&#039;

and for you old school sed peeps (sed args aren&#039;t as obscure):

$ grep -rl OLDSTRING . &#124; xargs sed -i -e &#039;s/OLDSTRING/NEWSTRING/&#039;

In all of these cases, you can replace the grep command with `find . -type f`. I&#039;m guessing this hasn&#039;t been performance tested. I&#039;m also guessing for large files, just running the search and replace would be faster than scanning the file for matches, then scanning the file for matches AND replacing them.</description>
		<content:encoded><![CDATA[<p>Not sure why you run uniq on it, grep is perfectly capable of only returning unique results&#8230; And use the short options please. This should do just fine:</p>
<p>$ grep -rl OLDSTRING . | xargs perl -pi~ -e &#8216;s/OLDSTRING/NEWSTRING/&#8217;</p>
<p>and if you want to do it sorted, files (this will even do unique results too!):</p>
<p>$ grep -rl OLDSTRING . | sort -u | xargs perl -pi~ -e &#8216;s/OLDSTRING/NEWSTRING/&#8217;</p>
<p>and for you old school sed peeps (sed args aren&#8217;t as obscure):</p>
<p>$ grep -rl OLDSTRING . | xargs sed -i -e &#8216;s/OLDSTRING/NEWSTRING/&#8217;</p>
<p>In all of these cases, you can replace the grep command with `find . -type f`. I&#8217;m guessing this hasn&#8217;t been performance tested. I&#8217;m also guessing for large files, just running the search and replace would be faster than scanning the file for matches, then scanning the file for matches AND replacing them.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

