<?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>sed | /var/logs/paulooi.log</title>
	<atom:link href="https://logs.paulooi.com/tag/sed/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>
		<item>
		<title>Quick File Copy on File Name with Sample Extension</title>
		<link>https://logs.paulooi.com/quick-file-copy-on-file-name-with-sample-extension.php</link>
					<comments>https://logs.paulooi.com/quick-file-copy-on-file-name-with-sample-extension.php#comments</comments>
		
		<dc:creator><![CDATA[Paul Ooi]]></dc:creator>
		<pubDate>Tue, 18 May 2010 08:32:11 +0000</pubDate>
				<category><![CDATA[Systems]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[linux command]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[unix command]]></category>
		<guid isPermaLink="false">http://systems.takizo.com/?p=979</guid>

					<description><![CDATA[<p>By default, some of the application installation provide you a sample configuration file. Usually the sample of configuration will end with name like *.sample, *.default and so on. Let say you have 20 of *.sample files and it will take...</p>
The post <a href="https://logs.paulooi.com/quick-file-copy-on-file-name-with-sample-extension.php">Quick File Copy on File Name with Sample Extension</a> first appeared on <a href="https://logs.paulooi.com">/var/logs/paulooi.log</a>.]]></description>
										<content:encoded><![CDATA[<p>By default, some of the application installation provide you a sample configuration file. Usually the sample of configuration will end with name like *.sample, *.default and so on. Let say you have 20 of *.sample files and it will take you some time to copy, move or rename one by one. Lets do some quicker way which will save more time.</p>
<p>Create a sample file file random name ended with *.sample. Example </p>
<pre>
<code>
touch apple.sample.cfg
touch microsoft.sample.cfg
touch php.sample.cfg
touch config.sample.cfg
touch apache.sample.cfg
touch mysql.sample.cfg
touch pgsql.sample.cfg
touch cacti.sample.cfg
touch wordpress.sample.cfg
touch jessicaalba.sample.cfg
</code>
</pre>
<p>Now you have all the sample configuration, you are going to use them. Are you going to copy one by another and change the same with .cfg prefix? We can do it, in a better and faster way. </p>
<p>Make a new directory to store all the sample file </p>
<pre>
<code>
mkdir sample
cp *.sample.cfg sample/
</code>
</pre>
<p>After that, go to sample directory and copy the files to a location </p>
<pre>
<code>
cd sample 
for d  in `ls *.sample.cfg`; do cp $d `echo $d | sed s/sample.cfg/cfg`; done
</code>
</pre>
<p>That one simple line will easily save you 1-2 minutes. </p>The post <a href="https://logs.paulooi.com/quick-file-copy-on-file-name-with-sample-extension.php">Quick File Copy on File Name with Sample Extension</a> first appeared on <a href="https://logs.paulooi.com">/var/logs/paulooi.log</a>.]]></content:encoded>
					
					<wfw:commentRss>https://logs.paulooi.com/quick-file-copy-on-file-name-with-sample-extension.php/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
