<?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: Replace string1 with string2 in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730149#M836090</link>
    <description>Use sed&lt;BR /&gt;&lt;BR /&gt;I would use...&lt;BR /&gt;&lt;BR /&gt;for i in `cat filelist`&lt;BR /&gt;do&lt;BR /&gt;sed 's/string1/string2/g' $i &amp;gt; $i.new&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;you can then move or copy, whatever suits you, the new file to the original&lt;BR /&gt;&lt;BR /&gt;GL,&lt;BR /&gt;C</description>
    <pubDate>Thu, 23 May 2002 13:00:04 GMT</pubDate>
    <dc:creator>Craig Rants</dc:creator>
    <dc:date>2002-05-23T13:00:04Z</dc:date>
    <item>
      <title>Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730146#M836087</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I want to replace a string1 with a string2 in several acsii files using a script. What's the best and simpliest solution.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;Andrej</description>
      <pubDate>Thu, 23 May 2002 12:55:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730146#M836087</guid>
      <dc:creator>Andrej Vavro</dc:creator>
      <dc:date>2002-05-23T12:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730147#M836088</link>
      <description>HI,&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;for i in $(ls)&lt;BR /&gt;do&lt;BR /&gt;sed 's%string1%string2%g' $i &amp;gt;$i.new&lt;BR /&gt;mv $i $i.org&lt;BR /&gt;mv $i.new $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;HtH,&lt;BR /&gt;&lt;BR /&gt;Mark</description>
      <pubDate>Thu, 23 May 2002 12:58:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730147#M836088</guid>
      <dc:creator>Mark van Hassel</dc:creator>
      <dc:date>2002-05-23T12:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730148#M836089</link>
      <description>There is no way of doing this unless you make temp copies of your data.  (or go interactive)&lt;BR /&gt;&lt;BR /&gt;sed allows string replacement and is very good.&lt;BR /&gt;TMPFILE=/tmp/temp.txt&lt;BR /&gt;if [ -f $TMPFILE ] ; then&lt;BR /&gt;rm -f $TMPFILE&lt;BR /&gt;fi&lt;BR /&gt;touch $TMPFILE&lt;BR /&gt;cat myascii.txt | sed -e s/"string1"/"string2"/g &amp;gt;&amp;gt;$TMPFILE&lt;BR /&gt;&lt;BR /&gt;Pattern matching is difficult to grok, so if your not good with pattern matching I'll recommend "SED and AWK" published by O'Reilly and Associates.  The first 2 chapters are dedicated to this concept.&lt;BR /&gt;for more info on args to sed, see:&lt;BR /&gt;man sed&lt;BR /&gt;Regards,&lt;BR /&gt;Shannon</description>
      <pubDate>Thu, 23 May 2002 12:59:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730148#M836089</guid>
      <dc:creator>Shannon Petry</dc:creator>
      <dc:date>2002-05-23T12:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730149#M836090</link>
      <description>Use sed&lt;BR /&gt;&lt;BR /&gt;I would use...&lt;BR /&gt;&lt;BR /&gt;for i in `cat filelist`&lt;BR /&gt;do&lt;BR /&gt;sed 's/string1/string2/g' $i &amp;gt; $i.new&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;you can then move or copy, whatever suits you, the new file to the original&lt;BR /&gt;&lt;BR /&gt;GL,&lt;BR /&gt;C</description>
      <pubDate>Thu, 23 May 2002 13:00:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730149#M836090</guid>
      <dc:creator>Craig Rants</dc:creator>
      <dc:date>2002-05-23T13:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730150#M836091</link>
      <description>#!/usr/bin/sh &lt;BR /&gt;# &lt;BR /&gt;# replace text in file &lt;BR /&gt;# &lt;BR /&gt;#set -x &lt;BR /&gt;&lt;BR /&gt;if [ $# -lt 3 ]; &lt;BR /&gt;then &lt;BR /&gt;echo "$0 old new /file.xml" &lt;BR /&gt;exit 1 &lt;BR /&gt;fi &lt;BR /&gt;&lt;BR /&gt;typeset OLD=$1 &lt;BR /&gt;typeset NEW=$2 &lt;BR /&gt;typeset FILE=$3 &lt;BR /&gt;&lt;BR /&gt;# cleanup &lt;BR /&gt;&lt;BR /&gt;# kludge for sed end of file 'bug' &lt;BR /&gt;echo "" &amp;gt;&amp;gt; $FILE &lt;BR /&gt;&lt;BR /&gt;# don't want to look at binaries &lt;BR /&gt;sed "s:$OLD:$NEW:g" $FILE &amp;gt; ${FILE}.bak &lt;BR /&gt;cp $FILE.bak $FILE &lt;BR /&gt;&lt;BR /&gt;# summarise &lt;BR /&gt;#.end. &lt;BR /&gt;</description>
      <pubDate>Thu, 23 May 2002 13:02:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730150#M836091</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2002-05-23T13:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730151#M836092</link>
      <description>Hi Andrei,&lt;BR /&gt;&lt;BR /&gt; Use sed&lt;BR /&gt;Create a file containing the list of files you wish to work on.&lt;BR /&gt;&lt;BR /&gt;Then use &lt;BR /&gt;&lt;BR /&gt;for x in filelist&lt;BR /&gt;do&lt;BR /&gt;sed 's/oldstring/newstring/g $x &amp;gt;$x.out&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;You can include a mv command if you don't wish to keep the org file. The g forces the search/replace globally in the file - w/o it, it will only work on the first occurrence.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Jeff</description>
      <pubDate>Thu, 23 May 2002 13:03:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730151#M836092</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2002-05-23T13:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730152#M836093</link>
      <description>#!/usr/bin/ksh&lt;BR /&gt;find /tmp -type f | while read FNAME&lt;BR /&gt;do&lt;BR /&gt;sed "s/OLDSTRING/NEWSTRING/g" &amp;lt; ${FNAME} &amp;gt; ${FNAME}.tmp&lt;BR /&gt;mv ${FNAME}.tmp $FNAME&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 23 May 2002 13:04:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730152#M836093</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-05-23T13:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730153#M836094</link>
      <description>Sed is the simplest, not neccessarily the best . Assuming the dir has only files.&lt;BR /&gt;# cd /dirA&lt;BR /&gt;# for file in `ls`&lt;BR /&gt;&amp;gt;do&lt;BR /&gt;&amp;gt;sed 's/string1/string2/g' $file &amp;gt; $file.replaced&lt;BR /&gt;&amp;gt;done&lt;BR /&gt;&lt;BR /&gt;Also check out some handy one-liner sed ..&lt;BR /&gt;&lt;A href="http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html" target="_blank"&gt;http://www-h.eng.cam.ac.uk/help/tpl/unix/sed.html&lt;/A&gt;</description>
      <pubDate>Thu, 23 May 2002 13:04:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730153#M836094</guid>
      <dc:creator>S.K. Chan</dc:creator>
      <dc:date>2002-05-23T13:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730154#M836095</link>
      <description>Script that'll do it recursively from dir.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x2a77abe92dabd5118ff10090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x2a77abe92dabd5118ff10090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Later,&lt;BR /&gt;Bill</description>
      <pubDate>Thu, 23 May 2002 13:06:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730154#M836095</guid>
      <dc:creator>Bill McNAMARA_1</dc:creator>
      <dc:date>2002-05-23T13:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730155#M836096</link>
      <description>Sorry - left out the ending single quote in the sed command line. And if white space in the string you'll need quotes around it - doesn't hurt to use 'em even if no white space.&lt;BR /&gt;Should be as follows&lt;BR /&gt;&lt;BR /&gt;sed 's/"oldstring"/"newstring"/g' $x &amp;gt;$x.out &lt;BR /&gt;&lt;BR /&gt;Jeff&lt;BR /&gt;</description>
      <pubDate>Thu, 23 May 2002 13:10:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730155#M836096</guid>
      <dc:creator>Jeff Schussele</dc:creator>
      <dc:date>2002-05-23T13:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730156#M836097</link>
      <description>I think I will give you a really cool way to do this that takes care of all the temp file stuff behind the scenes and will even optionally create a backup.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;perl -i.save -p -e 's/oldstring/newstring/g' myfile1 myfile2 myfile3&lt;BR /&gt;&lt;BR /&gt;That will edit each of the files 'on the fly' and create a backup copy of each file myfile1.save, myfile2.save. If you don't need the backup copy simply use -i rather than -i.suffix.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 May 2002 13:14:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730156#M836097</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-05-23T13:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Replace string1 with string2</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730157#M836098</link>
      <description>Hey, Clay, that's *my* clue :)&lt;BR /&gt;Finaly using the command line switches hay?&lt;BR /&gt;Good explanation too. Something I would (deliberately) omit. Users might want to use the docs to also learn something instead of just devour what they get thrown in their hands ...&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e 's/old/new/' files&lt;BR /&gt;&lt;BR /&gt;would have been my answer.&lt;BR /&gt;&lt;BR /&gt;N/A</description>
      <pubDate>Thu, 23 May 2002 13:52:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-string1-with-string2/m-p/2730157#M836098</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-05-23T13:52:23Z</dc:date>
    </item>
  </channel>
</rss>

