<?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: Trying this agian... Find and replace text string script. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012459#M128857</link>
    <description>To further expand Brians answer&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;for file in $(ls -R)&lt;BR /&gt;do&lt;BR /&gt;if [-f $file]&lt;BR /&gt;then&lt;BR /&gt;vi $file &amp;lt;&amp;lt; EOF&lt;BR /&gt;:1,$ s/serverA/serverB/g&lt;BR /&gt;:wq!&lt;BR /&gt;EOF&lt;BR /&gt;elif [-d $file]&lt;BR /&gt;then&lt;BR /&gt;newfile=$(echo $file ex "s/serverA/serverB/g")&lt;BR /&gt;mv $file $newfile&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This will EDIT the files &amp;amp; move the directories.  I have not tested it, so you may need to tweek.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Tim</description>
    <pubDate>Tue, 01 Jul 2003 17:17:31 GMT</pubDate>
    <dc:creator>Tim D Fulford</dc:creator>
    <dc:date>2003-07-01T17:17:31Z</dc:date>
    <item>
      <title>Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012454#M128852</link>
      <description>Ok... I'm really new to this and want to make sure I'm being clear with what I'm trying to do... so I will try and break it down even further.&lt;BR /&gt;&lt;BR /&gt;I have copied a directory to my local machine (not testing with production data) &lt;BR /&gt;I need to search for a string of text, that being 'serverA' and change it to 'serverB'. Now I know for a fact that this sting of text will be located in 100's of text files and even be part of directory names. This string of text 'serverA' is located in literally hundreds of places with in this directory and all of the sub-directories under it. When the string of text "serverA" is located I need to replace that string of text "serverA" with the new sting of text "serverB". So in short I need to replace 'serverA' which is located both inside files and directory names.&lt;BR /&gt;&lt;BR /&gt;I thought someone provided the answer on my previous post but after further investigation none of the text strings were replaced.&lt;BR /&gt;&lt;BR /&gt;Thank you again for all of your help.</description>
      <pubDate>Tue, 01 Jul 2003 16:33:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012454#M128852</guid>
      <dc:creator>Lowell Lindeman</dc:creator>
      <dc:date>2003-07-01T16:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012455#M128853</link>
      <description>I'm attaching a script that works for this.&lt;BR /&gt;&lt;BR /&gt;Its a perl script.&lt;BR /&gt;&lt;BR /&gt;It scans for text, creates a filelist and makes the change.&lt;BR /&gt;&lt;BR /&gt;Hope it helps.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Tue, 01 Jul 2003 16:36:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012455#M128853</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2003-07-01T16:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012456#M128854</link>
      <description>Lowell,&lt;BR /&gt;&lt;BR /&gt;I think you did get good answers in the previous thread, but I would suggest you break this down into two passes:  one for files using "find -type f" and one for directories using "find -type d" as the processing requirements will be different.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Jul 2003 16:37:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012456#M128854</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2003-07-01T16:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012457#M128855</link>
      <description>Hey Lowell,&lt;BR /&gt;&lt;BR /&gt;The following will work for making changes within a file that you have open with vi.&lt;BR /&gt;&lt;BR /&gt;:g/serverA/s//serverB/g&lt;BR /&gt;&lt;BR /&gt;This will make a global change of serverA to serverB, inside of a file...using vi. &lt;BR /&gt;&lt;BR /&gt;-Bryan</description>
      <pubDate>Tue, 01 Jul 2003 16:40:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012457#M128855</guid>
      <dc:creator>Bryan D. Quinn</dc:creator>
      <dc:date>2003-07-01T16:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012458#M128856</link>
      <description>You need to break down the problem into it's 2 components.  Finding the files with the text string you need replace and then editing and&lt;BR /&gt;replacing the text string in those files.  The&lt;BR /&gt;below command should work:&lt;BR /&gt;&lt;BR /&gt;grep -l serverA * | sed "s/serverA/serverB/g&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Jul 2003 17:09:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012458#M128856</guid>
      <dc:creator>William Wong_2</dc:creator>
      <dc:date>2003-07-01T17:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012459#M128857</link>
      <description>To further expand Brians answer&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;for file in $(ls -R)&lt;BR /&gt;do&lt;BR /&gt;if [-f $file]&lt;BR /&gt;then&lt;BR /&gt;vi $file &amp;lt;&amp;lt; EOF&lt;BR /&gt;:1,$ s/serverA/serverB/g&lt;BR /&gt;:wq!&lt;BR /&gt;EOF&lt;BR /&gt;elif [-d $file]&lt;BR /&gt;then&lt;BR /&gt;newfile=$(echo $file ex "s/serverA/serverB/g")&lt;BR /&gt;mv $file $newfile&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This will EDIT the files &amp;amp; move the directories.  I have not tested it, so you may need to tweek.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Tue, 01 Jul 2003 17:17:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012459#M128857</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2003-07-01T17:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012460#M128858</link>
      <description>If you use any of the perl script examples, be sure to download version 5.x. The default one under /usr/contrib/bin is version 4.x and is missing a lot of functionality.&lt;BR /&gt;&lt;BR /&gt;You haven't mentioned why none of the solutions are working. Some feedback could help the community give you a solution.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 01 Jul 2003 17:23:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012460#M128858</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-07-01T17:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012461#M128859</link>
      <description>Whoops actually I skipped one piece and flipped the order I verified that the following command worked:&lt;BR /&gt;&lt;BR /&gt;sed "s/serverA/serverB/g" `find . -type f -print | xargs grep -l serverA`&lt;BR /&gt;&lt;BR /&gt;That will find all the files from the directory you start the command from with the text string serverA and replace it with serverB.&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Jul 2003 17:25:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012461#M128859</guid>
      <dc:creator>William Wong_2</dc:creator>
      <dc:date>2003-07-01T17:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012462#M128860</link>
      <description>this script throws off the following output:&lt;BR /&gt;&lt;BR /&gt;sh [3]: [-f: not found.&lt;BR /&gt;sh [9]: [-d: not found.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;for file in $(ls -R)&lt;BR /&gt;do&lt;BR /&gt;if [-f $file]&lt;BR /&gt;then&lt;BR /&gt;vi $file &amp;lt;&amp;lt; EOF&lt;BR /&gt;:1,$ s/serverA/serverB/g&lt;BR /&gt;:wq!&lt;BR /&gt;EOF&lt;BR /&gt;elif [-d $file]&lt;BR /&gt;then&lt;BR /&gt;newfile=$(echo $file ex "s/serverA/serverB/g")&lt;BR /&gt;mv $file $newfile&lt;BR /&gt;fi&lt;BR /&gt;done</description>
      <pubDate>Tue, 01 Jul 2003 17:32:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012462#M128860</guid>
      <dc:creator>Lowell Lindeman</dc:creator>
      <dc:date>2003-07-01T17:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012463#M128861</link>
      <description>Willaim,&lt;BR /&gt;&lt;BR /&gt;Your script is running but it is not changing any of the files or directory names.&lt;BR /&gt;&lt;BR /&gt;Just trying to provide feed-back.&lt;BR /&gt;&lt;BR /&gt;Thanks again.</description>
      <pubDate>Tue, 01 Jul 2003 17:45:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012463#M128861</guid>
      <dc:creator>Lowell Lindeman</dc:creator>
      <dc:date>2003-07-01T17:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012464#M128862</link>
      <description>You asked this same thing in another thread, right? I'll repost my idea here too.&lt;BR /&gt;&lt;BR /&gt;for i in `find . -depth -exec grep -l 'serverA' {} \; | sed 's/\.\///'`&lt;BR /&gt;do&lt;BR /&gt;sed 's/serverA/serverB/' $i &amp;gt; $i.m&lt;BR /&gt;mv $i.m $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The first sed gets rid of the "./" from the find, assuming you're in the top of the directory you want to do the mods in. &lt;BR /&gt;&lt;BR /&gt;As for changing the directory names, it pretty much the same.&lt;BR /&gt;&lt;BR /&gt;for d in `find . -name *serverA* -type d -exec ls -d {} \; | sed 's/\.\///'`&lt;BR /&gt;do&lt;BR /&gt;mv $d $d.com&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Jul 2003 17:59:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012464#M128862</guid>
      <dc:creator>Robert Salter</dc:creator>
      <dc:date>2003-07-01T17:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012465#M128863</link>
      <description>I'm wrong on the directory name change, I'm taking too much for granted as to how your directories are named. Maybe I should just keep to reading and not trying to answer.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Jul 2003 18:03:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012465#M128863</guid>
      <dc:creator>Robert Salter</dc:creator>
      <dc:date>2003-07-01T18:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012466#M128864</link>
      <description>Williams script is not updating the original files because "sed" reads from stdin (can be multiple files) and writes ONE stdout file.&lt;BR /&gt;&lt;BR /&gt;You can use "sed" as long as you iterate over each filename, have sed input each file one at a time, output the result to one file, and then replace the original file with the newly created output file.&lt;BR /&gt;&lt;BR /&gt;A more efficient "find" statement would be-&lt;BR /&gt;&lt;BR /&gt;find . -print | xargs grep -l&lt;BR /&gt;&lt;BR /&gt;You original "find" calls grep for each filename. By using xargs you can call "grep" fewer times and reduce overhead and time.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 01 Jul 2003 18:10:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012466#M128864</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-07-01T18:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012467#M128865</link>
      <description>Williams script is not updating the original files because "sed" reads from stdin (can be multiple files) and writes ONE stdout file.&lt;BR /&gt;&lt;BR /&gt;You can use "sed" as long as you iterate over each filename, have sed input each file one at a time, output the result to one file, and then replace the original file with the newly created output file.&lt;BR /&gt;&lt;BR /&gt;A more efficient "find" statement would be-&lt;BR /&gt;&lt;BR /&gt;find . -print | xargs grep -l "ServberA"&lt;BR /&gt;&lt;BR /&gt;You original "find" calls grep for each filename. By using xargs you can call "grep" fewer times and reduce overhead and time.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 01 Jul 2003 18:10:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012467#M128865</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-07-01T18:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012468#M128866</link>
      <description>Hello Rodney,&lt;BR /&gt;&lt;BR /&gt;Thank you for the update... but I'm lost... can you dumb it down for me a bit and give me more detail?&lt;BR /&gt;&lt;BR /&gt;Thank you.</description>
      <pubDate>Tue, 01 Jul 2003 18:19:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012468#M128866</guid>
      <dc:creator>Lowell Lindeman</dc:creator>
      <dc:date>2003-07-01T18:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012469#M128867</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;This is one way:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;FILE=/tmp/results&lt;BR /&gt;cd /tmp/dummydir #...change this...&lt;BR /&gt;find . -type f -print|xargs grep -l serverA &amp;gt; ${FILE}&lt;BR /&gt;while read INPF X&lt;BR /&gt;do&lt;BR /&gt; sed -e 's/serverA/serverB/g' ${INPF} &amp;gt; ${INPF}.new&lt;BR /&gt; [ -f "${INPF}.new" ] &amp;amp;&amp;amp; mv ${INPF}.new ${INPF}&lt;BR /&gt;done &amp;lt; ${FILE}&lt;BR /&gt;rm ${FILE}&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 01 Jul 2003 18:27:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012469#M128867</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2003-07-01T18:27:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012470#M128868</link>
      <description>OK, so I got wrapped in this, so try this.&lt;BR /&gt;&lt;BR /&gt;for i in `find . -name *serverA* -type d -exec ls -d {} \;`&lt;BR /&gt;do&lt;BR /&gt;echo $i&lt;BR /&gt;newdir=`echo $i |sed 's/serverA/serverB/' `&lt;BR /&gt;mv $i $newdir&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;make a backup before trying anyhting.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 01 Jul 2003 18:43:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012470#M128868</guid>
      <dc:creator>Robert Salter</dc:creator>
      <dc:date>2003-07-01T18:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012471#M128869</link>
      <description>Way back up the thread I provided a script (that did not work!!)&lt;BR /&gt;&lt;BR /&gt;the "if [ -f $file ]"  means if $file is a file, and "elif [ -d $file ]" mean else if $file is a directory.  They SHOULD work if not try man ksh &amp;amp; look for the relavent section.  Currently I'm @home &amp;amp; do not have a computer to try this out on (sorry :-( )&lt;BR /&gt;&lt;BR /&gt;Alternatively there are alot of replies using find (an fine solution, probably more efficient too)&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Tue, 01 Jul 2003 19:37:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012471#M128869</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2003-07-01T19:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Trying this agian... Find and replace text string script.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012472#M128870</link>
      <description>James example is what I was talking about. He iterates over each of the filenames. Executes sed on each one generating a new file. Moves the new file into the original.&lt;BR /&gt;&lt;BR /&gt;Unix shell programming can be frustrating at first, but with experience it can do some fantastic things (and perl even more so)!&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 01 Jul 2003 19:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/trying-this-agian-find-and-replace-text-string-script/m-p/3012472#M128870</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-07-01T19:50:29Z</dc:date>
    </item>
  </channel>
</rss>

