<?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>LosByers- Interesting Musings Helpful Hints from a Unix System Administrator &#187; Coding</title>
	<atom:link href="http://losbyers.com/wordpress/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://losbyers.com/wordpress</link>
	<description>All the info I need</description>
	<lastBuildDate>Fri, 10 Sep 2010 04:56:38 +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>Command Line Search and Replace</title>
		<link>http://losbyers.com/wordpress/2009/12/command-line-search-and-replace/</link>
		<comments>http://losbyers.com/wordpress/2009/12/command-line-search-and-replace/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 22:02:17 +0000</pubDate>
		<dc:creator>LosByers</dc:creator>
				<category><![CDATA[Unix]]></category>
		<category><![CDATA[Web Related]]></category>
		<category><![CDATA[Windows OS]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[KSH]]></category>

		<guid isPermaLink="false">http://losbyers.com/wordpress/?p=39</guid>
		<description><![CDATA[<p>So you want to change some text in many unix files.</p>
<p>Try the following.</p>
<p>perl -pi -e &#8217;s/find/replace/g&#8217; *.txt</p>
<p>or to script it out.
Find the TEXT in regular files and replace with NEWTEXT</p>
<p>for file in `find ./ -type f -exec grep -l TEXT {} \;`
do
perl -pi -e &#8217;s/TEXT/NEWTEXT/g&#8217; $file 
done </p>
<p>I found out how to pass KSH variables [...]]]></description>
			<content:encoded><![CDATA[<p><span>So you want to change some text in many unix files.</p>
<p>Try the following.</p>
<p>perl -pi -e &#8217;s/find/replace/g&#8217; *.txt</p>
<p>or to script it out.<br />
Find the TEXT in regular files and replace with NEWTEXT</p>
<p>for file in `find ./ -type f -exec grep -l TEXT {} \;`<br />
do<br />
<strong>perl -pi -e &#8217;s/TEXT/NEWTEXT/g&#8217; $file </strong><br />
done </span></p>
<p><span><span id="more-39"></span></span><span>I found out how to pass KSH variables to awk, just in case this ever comes in handy.</p>
<p><span style="font-weight: bold;">VAR=&#8221;some_data&#8221;</p>
<p>echo &#8220;This is nice&#8221; | awk &#8216;{ print $1, avar, $2, $3 }&#8217; avar=$VAR</span></p>
<p>&gt; This some_data is nice</p>
<p>Or a better example; Changing file names.</p>
<p><span style="font-weight: bold;">VAR=&#8221;.poop&#8221;<br />
for x in *.php<br />
do<br />
echo &#8220;moving $x to \c&#8221; ;echo $x | awk -F. &#8216;{ print $1 newext }&#8217; newext=$VAR<br />
mv $x `echo $x | awk -F. &#8216;{ print $1 newext }&#8217; newext=$VAR&#8217;`<br />
done</span></p>
<p>&gt; moving test1.php to test1.poop<br />
&gt; moving test2.php to test2.poop<br />
&gt; moving test3.php to test3.poop</p>
<p>Of course if you had a file called test.this.file.php the awk statement above would mv it to test.poop and drop the other items after the first period.  There is probably a nice way to code around this, but hey, this works. for now.</span></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Flosbyers.com%2Fwordpress%2F2009%2F12%2Fcommand-line-search-and-replace%2F&amp;linkname=Command%20Line%20Search%20and%20Replace"><img src="http://losbyers.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://losbyers.com/wordpress/2009/12/command-line-search-and-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
