<?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>Simon Ottenhaus &#187; Preg</title>
	<atom:link href="http://familie-ottenhaus.de/simon/blog/tag/preg/feed/" rel="self" type="application/rss+xml" />
	<link>http://familie-ottenhaus.de/simon/blog</link>
	<description>Uni &#38; Software</description>
	<lastBuildDate>Tue, 21 Feb 2012 18:27:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>HowTo: Textersetzung in mehreren Dateien mit Perl (preg) unter Windows und Linux</title>
		<link>http://familie-ottenhaus.de/simon/blog/2009/11/howto-textersetzung-in-mehreren-dateien-mit-perl-preg-unter-windows-und-linux/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2009/11/howto-textersetzung-in-mehreren-dateien-mit-perl-preg-unter-windows-und-linux/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:16:47 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[HowTo / Anleitung]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Preg]]></category>
		<category><![CDATA[Textersetzung]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=916</guid>
		<description><![CDATA[Neulich stellte sich mir folgendes Problem: Ich hatte viele Dateien, in denen ich Text ersetzen wollte. Mit einem normalen Editor ist dies schlecht möglich. Abhilfe schafft der Perl Interpreter: View Code BASH1 2 3 4 5 6 7 8 perl -pi -w -e 's/search/replace/g;' *.html &#160; -e Argument ausführen &#40;execute&#41; -i &#34;in-place&#34; editieren -w Warnungen [...]]]></description>
			<content:encoded><![CDATA[<p>Neulich stellte sich mir folgendes Problem:<br />
Ich hatte viele Dateien, in denen ich Text ersetzen wollte. Mit einem normalen Editor ist dies schlecht möglich. Abhilfe schafft der Perl Interpreter:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p916code5'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p9165"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p916code5"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-w</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/search/replace/g;'</span> <span style="color: #000000; font-weight: bold;">*</span>.html
&nbsp;
    <span style="color: #660033;">-e</span> Argument ausführen <span style="color: #7a0874; font-weight: bold;">&#40;</span>execute<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;in-place&quot;</span> editieren
    <span style="color: #660033;">-w</span> Warnungen ausgeben
    <span style="color: #660033;">-p</span> <span style="color: #ff0000;">&quot;loop&quot;</span>
&nbsp;
siehe auch <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-h</span></pre></td></tr></table></div>

<h3>Beispiel Datum 1</h3>
<p>Es soll das Datum von 2008 auf 2009 in allen html-Dateien im aktuellen Verzeichnis aktualisiert werden:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p916code6'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p9166"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p916code6"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-w</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/2008/2009/g;'</span> <span style="color: #000000; font-weight: bold;">*</span>.html</pre></td></tr></table></div>

<h3>Beispiel Datum 2</h3>
<p>Es soll das Datum von 200x auf 2009 in allen html-Dateien im aktuellen Verzeichnis aktualisiert werden:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p916code7'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p9167"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p916code7"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-w</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/200[0-8]/2009/g;'</span> <span style="color: #000000; font-weight: bold;">*</span>.html</pre></td></tr></table></div>

<h3>Beispiel: Verzeichnisse rekursiv durchsuchen (nur Linux)</h3>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p916code8'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p9168"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p916code8"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;\.html$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-w</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/search/replace/g;'</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">*</span> gibt alle Dateien und Verzeichnisse aus
    <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;\.html$&quot;</span> selektiert nur Dateinamen, die auf .html enden
    <span style="color: #c20cb9; font-weight: bold;">xargs</span> gibt die Dateinamen als Parameter an Perl weiter</pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2009/11/howto-textersetzung-in-mehreren-dateien-mit-perl-preg-unter-windows-und-linux/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2009/11/howto-textersetzung-in-mehreren-dateien-mit-perl-preg-unter-windows-und-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

