<?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 how to replace strings in multiple files thru script or command line in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342494#M874944</link>
    <description>Hi:&lt;BR /&gt;I have "n" files in a directory and I want to search for A/B/C/D and replace it with E/F/G/H/I in all the files thru a script or on a command line. I have to do this on 6 servers so .. &lt;BR /&gt;&lt;BR /&gt;any suggestions</description>
    <pubDate>Tue, 27 Jul 2004 13:56:11 GMT</pubDate>
    <dc:creator>Sachin_29</dc:creator>
    <dc:date>2004-07-27T13:56:11Z</dc:date>
    <item>
      <title>how to replace strings in multiple files thru script or command line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342494#M874944</link>
      <description>Hi:&lt;BR /&gt;I have "n" files in a directory and I want to search for A/B/C/D and replace it with E/F/G/H/I in all the files thru a script or on a command line. I have to do this on 6 servers so .. &lt;BR /&gt;&lt;BR /&gt;any suggestions</description>
      <pubDate>Tue, 27 Jul 2004 13:56:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342494#M874944</guid>
      <dc:creator>Sachin_29</dc:creator>
      <dc:date>2004-07-27T13:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace strings in multiple files thru script or command line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342495#M874945</link>
      <description># cd /dir&lt;BR /&gt;# for FILE in *&lt;BR /&gt;do&lt;BR /&gt;  mv $FILE $FILE.tmp&lt;BR /&gt;  sed 's|A/B/C/D|E/F/G/H/I|' $FILE.tmp &amp;gt; $FILE&lt;BR /&gt;  [ $? -eq 0 ] &amp;amp;&amp;amp; rm $FILE.tmp&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jul 2004 14:00:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342495#M874945</guid>
      <dc:creator>Sundar_7</dc:creator>
      <dc:date>2004-07-27T14:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace strings in multiple files thru script or command line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342496#M874946</link>
      <description>I think I would leverage sed to do this although Perl would also be a good choice.&lt;BR /&gt;&lt;BR /&gt;1) Create a file, /var/tmp/x.sed, and insert your replacement instructions.&lt;BR /&gt;&lt;BR /&gt;I'll use '+' as the delimiter because that will make your "/" replacements easier.&lt;BR /&gt;&lt;BR /&gt;s+A/B/C/D+E/F/G/H/I+g&lt;BR /&gt;&lt;BR /&gt;You can put as many sed commands in this file as your like; they will be processed sequentially on each file.&lt;BR /&gt;&lt;BR /&gt;2) Create a script to find the text files in the current directory and sed them.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;TFILE=${TDIR}/X${$}_1.txt&lt;BR /&gt;SEDFILE=/var/tmp/x.sed&lt;BR /&gt;&lt;BR /&gt;STAT=0&lt;BR /&gt;ls | while read X &lt;BR /&gt;  do&lt;BR /&gt;     file "${X}" | grep -q -i "text"&lt;BR /&gt;     STAT=${?}&lt;BR /&gt;     if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;       then&lt;BR /&gt;         sed -f ${SEDFILE} "${X}" &amp;gt; ${TFILE}&lt;BR /&gt;         STAT=${?}&lt;BR /&gt;         if [[ ${STAT} -eq 0 ]]&lt;BR /&gt;           then&lt;BR /&gt;             mv ${TFILE} "${X}"&lt;BR /&gt;           fi&lt;BR /&gt;       fi&lt;BR /&gt;  done&lt;BR /&gt;exit ${STAT}&lt;BR /&gt;                 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jul 2004 14:20:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342496#M874946</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-07-27T14:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace strings in multiple files thru script or command line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342497#M874947</link>
      <description>A one line perl command would be:&lt;BR /&gt; &lt;BR /&gt;perl -p -i -e 's{A/B/C/D}{E/F/G/H/I}g' *&lt;BR /&gt; &lt;BR /&gt;If you have openssh installed, you could run it on each of the servers by:&lt;BR /&gt;&lt;BR /&gt;for x in server1 server2 server3 ; do&lt;BR /&gt; ssh $x "cd /mydir ; perl -p -i -e 's{A/B/C/D}{E/F/G/H/I}g' *"&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 27 Jul 2004 15:38:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342497#M874947</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-07-27T15:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace strings in multiple files thru script or command line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342498#M874948</link>
      <description>This is simple change of string on specific file on multiple servers. &lt;BR /&gt;&lt;BR /&gt;for i in `cat serverlist` &lt;BR /&gt;do &lt;BR /&gt;remsh $i "sed 's/stringA/stringB/g' /dir/fileX"&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Jul 2004 01:03:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342498#M874948</guid>
      <dc:creator>Petr Simik_1</dc:creator>
      <dc:date>2004-07-30T01:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace strings in multiple files thru script or command line</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342499#M874949</link>
      <description>IF you want to change the pattern with in one directory then grep and sed will do that, if you want to do it multiple directories we have to use find,grep and sed commands&lt;BR /&gt;&lt;BR /&gt; Limitation: If we use grep to grep a pattern on a object file ,it will make a lot of error and unreadable symbols.&lt;BR /&gt;&lt;BR /&gt; In a single directory:&lt;BR /&gt;find . -name "*" -exec grep -q 'A/B/C/D' {} \; -print | awk '{ print "echo \"`sed -e 's%A/B/C/D%E/F/G/H%' "$1"`\"&amp;gt; "$1 }' | sh&lt;BR /&gt;&lt;BR /&gt; Multiple directory:&lt;BR /&gt;&lt;BR /&gt; Change find . to your testing directory. It will do this in their subdirectories too.&lt;BR /&gt;&lt;BR /&gt; Use -type f instead of -name "*" also</description>
      <pubDate>Fri, 30 Jul 2004 02:01:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-replace-strings-in-multiple-files-thru-script-or-command/m-p/3342499#M874949</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-07-30T02:01:08Z</dc:date>
    </item>
  </channel>
</rss>

