<?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>RedHatVN Network &#124; Ho Tro Linux &#124; Support Linux &#124; Linux VN &#187; sed</title>
	<atom:link href="http://redhatvn.net/tag/sed/feed" rel="self" type="application/rss+xml" />
	<link>http://redhatvn.net</link>
	<description>Shared Linux problems</description>
	<lastBuildDate>Fri, 03 Sep 2010 08:03:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Bash Shell: Replace a string with another string in all files using sed and perl -pie</title>
		<link>http://redhatvn.net/bash-shell-replace-a-string-with-another-string-in-all-files-using-sed-and-perl-pie</link>
		<comments>http://redhatvn.net/bash-shell-replace-a-string-with-another-string-in-all-files-using-sed-and-perl-pie#comments</comments>
		<pubDate>Thu, 27 Aug 2009 09:22:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://redhatvn.net/?p=269</guid>
		<description><![CDATA[Q. How do I replace a string with another string in all files? For example, ~/foo directory has 100s of text file and I&#8217;d like to find out xyz string and replace with abc. I&#8217;d like to use sed or any other tool to replace all occurrence of the word. A.sed command is designed for [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">Q.</span> How do I replace a string with another string in all files? For example, ~/foo directory has 100s of text file and I&#8217;d like to find out xyz string and replace with abc. I&#8217;d like to use sed or any other tool to replace all occurrence of the word.</p>
<p><span style="color: #009900;">A</span>.sed command is designed for this kind of work i.e. replace strings.</p>
<p><span id="more-269"></span></p>
<h2>sed replace word / string syntax</h2>
<p><code>sed -i 's/<span style="color: #ff0000;">old-word</span>/<span style="color: #993399;">new-word</span>/g' *.txt</code></p>
<p>GNU sed command can edit files in place (makes backup if extension supplied) using -i option. If you are using old or UNIX sed command try the following syntax:</p>
<p><code>sed 's/<span style="color: #993399;">old</span>/<span style="color: #ff9900;">new</span>/g' input.txt &gt; output.txt</code></p>
<p>I recommend using old syntax along with for loop:</p>
<blockquote><p>
#!/bin/bash<br />
OLD=&#8221;xyz&#8221;<br />
NEW=&#8221;abc&#8221;<br />
DPATH=&#8221;/home/you/foo/*.txt&#8221;<br />
BPATH=&#8221;/home/you/bakup/foo&#8221;<br />
TFILE=&#8221;/tmp/out.tmp.$$&#8221;<br />
[ ! -d $BPATH ] &amp;&amp; mkdir -p $BPATH || :<br />
for f in $DPATH<br />
do<br />
  if [ -f $f -a -r $f ]; then<br />
    /bin/cp -f $f $BPATH<br />
   sed &#8220;s/$OLD/$NEW/g&#8221; &#8220;$f&#8221; &gt; $TFILE &amp;&amp; mv $TFILE &#8220;$f&#8221;<br />
  else<br />
   echo &#8220;Error: Cannot read $f&#8221;<br />
  fi<br />
done<br />
/bin/rm $TFILE</p></blockquote>
<h2>perl -pie trick</h2>
<p><code>perl -pie 's/<span style="color: #993399;">old-word</span>/<span style="color: #ff9900;">new-word</span>/g' input &gt; output</code></p>
]]></content:encoded>
			<wfw:commentRss>http://redhatvn.net/bash-shell-replace-a-string-with-another-string-in-all-files-using-sed-and-perl-pie/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>sed Case Insensitive Search Matching</title>
		<link>http://redhatvn.net/sed-case-insensitive-search-matching</link>
		<comments>http://redhatvn.net/sed-case-insensitive-search-matching#comments</comments>
		<pubDate>Thu, 27 Aug 2009 09:09:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://redhatvn.net/?p=262</guid>
		<description><![CDATA[Q. How do I perform a case-insensitive search using sed under UNIX / Linux? I&#8217;d like to match all combination of word &#8211; foo, FOO, FoO and so on while replacing or performing other operations. A. GNU sed and other version does support a case-insensitive search using I flag after /regex/. UNIX / Linux: sed [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">Q.</span> How do I perform a case-insensitive search using sed under UNIX / Linux? I&#8217;d like to match all combination of word &#8211; foo, FOO, FoO and so on while replacing or performing other operations.</p>
<p><span style="color: #009900;">A. </span>GNU sed and other version does support a case-insensitive search using I flag after /regex/.</p>
<p><span id="more-262"></span></p>
<h2>UNIX / Linux: sed Case Insensitive Search</h2>
<p>To perform a case-insensitive search, enter:</p>
<blockquote><p><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #c20cb9; font-weight: bold;">file</span>.txt | <span style="color: #c20cb9; font-weight: bold;">sed</span> -e <span style="color: #ff0000;">&#8216;s/find-word/replace-word/gI&#8217;</span><br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #c20cb9; font-weight: bold;">file</span>.txt | <span style="color: #c20cb9; font-weight: bold;">sed</span> -e <span style="color: #ff0000;">&#8216;s/find-word/replace-word/gI&#8217;</span> &gt; output.txt<br />
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&#8216;s/find-word/replace-word/gI&#8217;</span> input.txt &gt; output.txt</p></blockquote>
<p>If you are using older sed version try,</p>
<blockquote><p><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&#8216;s/[wW][oO][rR][dD]/replace-word/g&#8217;</span> input.txt &gt; output.txt</p></blockquote>
<p>It is easy to match first few characters, for example match both Linux and linux word:</p>
<blockquote><p><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">&#8216;s/[Ll]inux/Unix/g&#8217;</span> input.txt &gt; output.txt</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://redhatvn.net/sed-case-insensitive-search-matching/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->