<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>We Heart Code &#187; perl</title>
	<atom:link href="http://www.weheartcode.com/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weheartcode.com</link>
	<description>A discourse on programming</description>
	<lastBuildDate>Sun, 17 Jan 2010 02:16:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Perl One Liner &#8211; Search Replace String in File</title>
		<link>http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/</link>
		<comments>http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/#comments</comments>
		<pubDate>Tue, 24 Oct 2006 12:35:32 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/</guid>
		<description><![CDATA[This is one of the most useful perl one-liners.  Search and Replace a string in a text file.


perl -0777 -i -pe 's/patterntomatch/replacewith/g' inputfile



Let's break this down
-0777: treat file as a single line, this way we don't have to worry about ranges on our regex.
-i: operate on file in place. super dangerous and fun. If [...]]]></description>
			<content:encoded><![CDATA[<p>This is one of the most useful perl one-liners.  Search and Replace a string in a text file.</p>
<div class="syntax_hilite">
<div id="code-2">
<div class="code">perl -<span style="color:#800000;">0777</span> -i -pe <span style="color:#CC0000;">'s/patterntomatch/replacewith/g'</span> inputfile</div>
</div>
</div>
<p></p>
<p>Let's break this down</p>
<p><strong>-0777</strong>: treat file as a single line, this way we don't have to worry about ranges on our regex.</p>
<p><strong>-i</strong>: operate on file in place. super dangerous <em>and fun</em>. If you're a big wuss you could use -i.bak to automatically create a backup file.</p>
<p><strong>-pe</strong>: loop over and print output.</p>
<!-- Social Bookmarks BEGIN --><div class="social_bookmark"><em>Bookmark to:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/&amp;title=Perl+One+Liner+%26%238211%3B+Search+Replace+String+in+File" title="Add 'Perl One Liner &#8211; Search Replace String in File' to Del.icio.us"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/delicious.png" title="Add 'Perl One Liner &#8211; Search Replace String in File' to Del.icio.us" alt="Add 'Perl One Liner &#8211; Search Replace String in File' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/&amp;title=Perl+One+Liner+%26%238211%3B+Search+Replace+String+in+File" title="Add 'Perl One Liner &#8211; Search Replace String in File' to digg"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/digg.png" title="Add 'Perl One Liner &#8211; Search Replace String in File' to digg" alt="Add 'Perl One Liner &#8211; Search Replace String in File' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://furl.net/storeIt.jsp?t=Perl+One+Liner+%26%238211%3B+Search+Replace+String+in+File&amp;u=http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/" title="Add 'Perl One Liner &#8211; Search Replace String in File' to FURL"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/furl.png" title="Add 'Perl One Liner &#8211; Search Replace String in File' to FURL" alt="Add 'Perl One Liner &#8211; Search Replace String in File' to FURL" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/&amp;title=Perl+One+Liner+%26%238211%3B+Search+Replace+String+in+File" title="Add 'Perl One Liner &#8211; Search Replace String in File' to reddit"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/reddit.png" title="Add 'Perl One Liner &#8211; Search Replace String in File' to reddit" alt="Add 'Perl One Liner &#8211; Search Replace String in File' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/" title="Add 'Perl One Liner &#8211; Search Replace String in File' to Technorati"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/technorati.png" title="Add 'Perl One Liner &#8211; Search Replace String in File' to Technorati" alt="Add 'Perl One Liner &#8211; Search Replace String in File' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/&amp;title=Perl+One+Liner+%26%238211%3B+Search+Replace+String+in+File" title="Add 'Perl One Liner &#8211; Search Replace String in File' to Google Bookmarks"><img src="http://www.weheartcode.com/wp-content/plugins/social_bookmarks/google.png" title="Add 'Perl One Liner &#8211; Search Replace String in File' to Google Bookmarks" alt="Add 'Perl One Liner &#8211; Search Replace String in File' to Google Bookmarks" /></a></div>
<!-- Social Bookmarks END -->]]></content:encoded>
			<wfw:commentRss>http://www.weheartcode.com/2006/10/24/perl-one-liner-search-replace-string-in-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
