<?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>replace | /var/logs/paulooi.log</title>
	<atom:link href="https://logs.paulooi.com/tag/replace/feed" rel="self" type="application/rss+xml" />
	<link>https://logs.paulooi.com</link>
	<description>Systems Admin, Web Development and etc</description>
	<lastBuildDate>Wed, 14 Jul 2010 04:54:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Linux/Unix Search and Replace Text from Multiple Files</title>
		<link>https://logs.paulooi.com/linuxunix-search-and-replace-text-from-multiple-files.php</link>
					<comments>https://logs.paulooi.com/linuxunix-search-and-replace-text-from-multiple-files.php#respond</comments>
		
		<dc:creator><![CDATA[Paul Ooi]]></dc:creator>
		<pubDate>Wed, 14 Jul 2010 04:50:02 +0000</pubDate>
				<category><![CDATA[Systems]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[unix]]></category>
		<guid isPermaLink="false">http://systems.takizo.com/?p=1029</guid>

					<description><![CDATA[<p>In Linux/Unix, for newbie to do search text from multiple files/folder look like difficult, replacing string from file sound even harder. It&#8217;s actually not hard or complicated to search and replace text from multiple files in Unix/Linux. The key is...</p>
The post <a href="https://logs.paulooi.com/linuxunix-search-and-replace-text-from-multiple-files.php">Linux/Unix Search and Replace Text from Multiple Files</a> first appeared on <a href="https://logs.paulooi.com">/var/logs/paulooi.log</a>.]]></description>
										<content:encoded><![CDATA[<p>In Linux/Unix, for newbie to do search text from multiple files/folder look like difficult, replacing string from file sound even harder. It&#8217;s actually not hard or complicated to search and replace text from multiple files in Unix/Linux. The key is what command to use, there will be two main commands involve in search and replace, which are <strong>find</strong> and <strong>sed</strong></p>
<p>For example I am hosting multiple web applications, the development might have several pg_connect command to connect database, in the event I am migrating database to other IP address, it might be hard for them to dig the file and replace the IP Address with new IP Addresses. </p>
<p>In Linux/Unix, you can search through the directories, looking for the files and replace it with the new IP address. Here is the sample. </p>
<pre>
<code>
shell> find /path/to/dir/* -type f -exec sed -i .backup20100714 -e "s/host=x.x.x.x/host=y.y.y.y/g" {} \\;
</code>
</pre>
<p>The command above will search for files in the directory.<br />
find -type f mean look for File only.<br />
find -exec is to execute something from returned results.<br />
sed -i means backup the files, in case you would like to restore later.<br />
sed -e &#8220;s/host=x.x.x.x/host=y.y.y.y/g&#8221; is to replace x.x.x.x to y.y.y.y</p>
<p>You have backup files name filename.php.backup20100714, now what you need to do is move the files in a backup directory. </p>
<pre>
<code>
shell> find /path/to/dir/* -name "*.backup20100714" -exec mv {} /your/backup/dir/ \\;
</code>
</pre>
<p>You might want to explore on <strong>find</strong> command, it can do a lot of cool stuffs.</p>The post <a href="https://logs.paulooi.com/linuxunix-search-and-replace-text-from-multiple-files.php">Linux/Unix Search and Replace Text from Multiple Files</a> first appeared on <a href="https://logs.paulooi.com">/var/logs/paulooi.log</a>.]]></content:encoded>
					
					<wfw:commentRss>https://logs.paulooi.com/linuxunix-search-and-replace-text-from-multiple-files.php/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
