<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: help me with search &amp;amp; replace string (quoting) in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691129#M638239</link>
    <description>&lt;P&gt;&amp;gt;I have 30000 files to modify, and I cannot change the filename.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's what scripting is for.&amp;nbsp; To handle &amp;gt; 1 cases.&lt;/P&gt;&lt;P&gt;If you have gnu sed or perl there is a -i option for in place update.&lt;/P&gt;&lt;P&gt;Otherwise you need to do something like:&lt;/P&gt;&lt;P&gt;sed&amp;nbsp; "s/$string1/$string2/g" $file &amp;gt; $file.new&lt;/P&gt;&lt;P&gt;if [ $? -eq 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; mv $file.new $file&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jun 2012 06:49:11 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2012-06-15T06:49:11Z</dc:date>
    <item>
      <title>help me with search &amp; replace string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5690341#M638235</link>
      <description>&lt;P&gt;Hi all&lt;BR /&gt;&lt;BR /&gt;Please can you help me with a script to check several files for the following string:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;encoding=""&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;and replace it with:&lt;/P&gt;&lt;PRE&gt;encoding="UTF-8"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I did the following, :&lt;/P&gt;&lt;PRE&gt;#!/bin/sh
string1="encoding="""
string2="encoding="UTF-8"
sed 's/'"$string1"'/'"$string2"'/g'&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;but does not work.&lt;BR /&gt;&lt;BR /&gt;Please can you help&lt;BR /&gt;&lt;BR /&gt;FR&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jun 2012 13:23:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5690341#M638235</guid>
      <dc:creator>NDO</dc:creator>
      <dc:date>2012-06-14T13:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5690365#M638236</link>
      <description />
      <pubDate>Thu, 14 Jun 2012 13:43:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5690365#M638236</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2012-06-14T13:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5690955#M638237</link>
      <description>&lt;P&gt;&amp;gt;but does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would help if you could also show the error.&amp;nbsp; As Steven said, it seems the only problem is in quoting string1 &amp;amp;&amp;nbsp;string2.&lt;/P&gt;&lt;P&gt;You should also remove the quote stuttering in the sed command:&lt;/P&gt;&lt;P&gt;sed "s/$string1/$string2/g"&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 02:57:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5690955#M638237</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-15T02:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691109#M638238</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It does work now, but only for one file and if I insert the file name after the "sed" command, like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;sed  "s/$string1/$string2/g" text2insert.txt &amp;gt; newfile.out&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I have 30000 files to modify, and I cannot change the filename.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FR&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 06:33:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691109#M638238</guid>
      <dc:creator>NDO</dc:creator>
      <dc:date>2012-06-15T06:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691129#M638239</link>
      <description>&lt;P&gt;&amp;gt;I have 30000 files to modify, and I cannot change the filename.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's what scripting is for.&amp;nbsp; To handle &amp;gt; 1 cases.&lt;/P&gt;&lt;P&gt;If you have gnu sed or perl there is a -i option for in place update.&lt;/P&gt;&lt;P&gt;Otherwise you need to do something like:&lt;/P&gt;&lt;P&gt;sed&amp;nbsp; "s/$string1/$string2/g" $file &amp;gt; $file.new&lt;/P&gt;&lt;P&gt;if [ $? -eq 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; mv $file.new $file&lt;/P&gt;&lt;P&gt;fi&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 06:49:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691129#M638239</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-15T06:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691145#M638240</link>
      <description>I am still in the learning phases of scripting, sorry if my next question is a dumb one:&lt;BR /&gt;&lt;BR /&gt;I presume I have to declare $file with the path where this xml files are located right?&lt;BR /&gt;&lt;BR /&gt;file="/xxx/www/lll.xml"&lt;BR /&gt;file.new="/xxx/www/zzz.xml"</description>
      <pubDate>Fri, 15 Jun 2012 06:56:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691145#M638240</guid>
      <dc:creator>NDO</dc:creator>
      <dc:date>2012-06-15T06:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691205#M638241</link>
      <description>&lt;P&gt;&amp;gt;I presume I have to declare $file with the path where this xml files are located right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes but not file.new, that's not a variable.&lt;/P&gt;&lt;P&gt;If you want to be pedantic about it:&lt;/P&gt;&lt;P&gt;sed&amp;nbsp; "s/$string1/$string2/g" ${file} &amp;gt; ${file}.new&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 07:13:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691205#M638241</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-15T07:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691223#M638242</link>
      <description>my biggest problem is really to understand the&lt;BR /&gt;&lt;BR /&gt;${file} &amp;gt; ${file}.new&lt;BR /&gt;&lt;BR /&gt;part of the script</description>
      <pubDate>Fri, 15 Jun 2012 07:23:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691223#M638242</guid>
      <dc:creator>NDO</dc:creator>
      <dc:date>2012-06-15T07:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691247#M638243</link>
      <description>&lt;P&gt;&amp;gt;my biggest problem is really to understand the ${file} &amp;gt; ${file}.new part of the script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;${file} needs to take on each of your 30,000 files you need to change.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 07:43:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691247#M638243</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-15T07:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691277#M638244</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the final script:&lt;/P&gt;&lt;PRE&gt;#!/bin/sh
file="/tmp/fr/danilo/"
string1="encoding="""
string2="encoding="UTF-8"
sed  "s/$string1/$string2/g" $file &amp;gt; $file.new

if [ $? -eq 0 ]; then

   mv $file.new $file

fi&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And this is the error I am having when I run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;mceldev[253]/tmp/fr/danilo #./mudar
./mudar[4]: Syntax error at line 5 : `"' is not matched.
mceldev[254]/tmp/fr/danilo #&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FR&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2012 08:12:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691277#M638244</guid>
      <dc:creator>NDO</dc:creator>
      <dc:date>2012-06-15T08:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691479#M638245</link>
      <description />
      <pubDate>Fri, 15 Jun 2012 11:13:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691479#M638245</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2012-06-15T11:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691873#M638246</link>
      <description>&lt;P&gt;&amp;gt;And this is the error I am having when I run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the same error that Steven told you how to fix before and again just now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;file="/tmp/fr/danilo/"&lt;/P&gt;&lt;P&gt;&amp;gt;sed "s/$string1/$string2/g" $file &amp;gt; $file.new&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your assignment to "file" above isn't going to work since will be treated as a directory path when adding ".new".&lt;/P&gt;&lt;P&gt;If you do want to scan/change mass quantities, you need to tell us how you&amp;nbsp;find those 30,000 files.&lt;/P&gt;&lt;P&gt;Also, the above code changes the file modification date, even if the string isn't found.&amp;nbsp; Do you want to not change the dates on those?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;If you do get the quotation marks into string1 and string2, what do you think will happen when you add more quotation marks to them, as in: "s/$string1/$string2/g"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure of your point?&amp;nbsp; If I got those double quotes into the strings (using single quotes), I had no problems with the sed command.&amp;nbsp; (At least with bash.&amp;nbsp; And a real shell works too.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wasn't sure so I explicitly checked it.&amp;nbsp; Reading the man page briefly may not provide enough detail to figure out what it does, so experiments are also helpful.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jun 2012 01:15:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691873#M638246</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-16T01:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691957#M638247</link>
      <description />
      <pubDate>Fri, 15 Jun 2012 21:55:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691957#M638247</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2012-06-15T21:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: help me with search &amp; replace string (quoting)</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691995#M638248</link>
      <description>&lt;P&gt;&amp;gt;It works for me, too. My usual quotation paranoia must be getting out of control.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, I didn't think it would be that easy either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It appears once something is quoted, it doesn't matter what the variables inside expand to.&lt;/P&gt;&lt;P&gt;Or course programs like sed and grep may need even more quoting.&amp;nbsp; :-)&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jun 2012 01:15:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-me-with-search-amp-replace-string/m-p/5691995#M638248</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-06-16T01:15:02Z</dc:date>
    </item>
  </channel>
</rss>

