<?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 Another way to do... in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267961#M889097</link>
    <description>Hi pals,&lt;BR /&gt;&lt;BR /&gt;At present I'm using the following script sintax to search in quit mode a key-word, then in the line where this key-word be, I need replace a specific string:&lt;BR /&gt;&lt;BR /&gt;ed $FILE &amp;lt;&amp;lt;-! &amp;gt; /dev/null&lt;BR /&gt;/$KEYWORD&lt;BR /&gt;s/$CURRENT_STRING/$NEW_STRING/&lt;BR /&gt;w&lt;BR /&gt;q&lt;BR /&gt;!&lt;BR /&gt;&lt;BR /&gt;This works fine, but any other secure/one-shot way to do this?&lt;BR /&gt;&lt;BR /&gt;Pls forget Perl.&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
    <pubDate>Wed, 05 May 2004 07:02:42 GMT</pubDate>
    <dc:creator>Jose Mosquera</dc:creator>
    <dc:date>2004-05-05T07:02:42Z</dc:date>
    <item>
      <title>Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267961#M889097</link>
      <description>Hi pals,&lt;BR /&gt;&lt;BR /&gt;At present I'm using the following script sintax to search in quit mode a key-word, then in the line where this key-word be, I need replace a specific string:&lt;BR /&gt;&lt;BR /&gt;ed $FILE &amp;lt;&amp;lt;-! &amp;gt; /dev/null&lt;BR /&gt;/$KEYWORD&lt;BR /&gt;s/$CURRENT_STRING/$NEW_STRING/&lt;BR /&gt;w&lt;BR /&gt;q&lt;BR /&gt;!&lt;BR /&gt;&lt;BR /&gt;This works fine, but any other secure/one-shot way to do this?&lt;BR /&gt;&lt;BR /&gt;Pls forget Perl.&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
      <pubDate>Wed, 05 May 2004 07:02:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267961#M889097</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2004-05-05T07:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267962#M889098</link>
      <description>awk '{if(index($0,"&lt;KEYWORD&gt;") &amp;gt; 0) sub("&lt;CURRENT_STRING&gt;","&lt;NEW_STRING&gt;"); print;}' $FILE&lt;BR /&gt;&lt;BR /&gt;this will change each single line that match your search criteria&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc&lt;/NEW_STRING&gt;&lt;/CURRENT_STRING&gt;&lt;/KEYWORD&gt;</description>
      <pubDate>Wed, 05 May 2004 07:23:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267962#M889098</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-05-05T07:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267963#M889099</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;cat $file | sed 's%$KEYWORD%$CURRENT_STRING/$NEW_STRING%g/' &amp;gt; $file.new &lt;BR /&gt;mv $file.new $file&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;&lt;BR /&gt;Gideon&lt;BR /&gt;</description>
      <pubDate>Wed, 05 May 2004 07:27:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267963#M889099</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2004-05-05T07:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267964#M889100</link>
      <description>Jean-Luc, &lt;BR /&gt;&lt;BR /&gt;Just a thing, it work perfectly if I use nawk instead of awk (sub is only available with nawk on some platform).&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Nicolas</description>
      <pubDate>Wed, 05 May 2004 07:30:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267964#M889100</guid>
      <dc:creator>Nicolas Dumeige</dc:creator>
      <dc:date>2004-05-05T07:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267965#M889101</link>
      <description>I think awk in HPUX is in fact the new awk (nawk).&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Wed, 05 May 2004 07:34:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267965#M889101</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-05-05T07:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267966#M889102</link>
      <description>nawk is for SUN. Since this is a HP-UX forum, and no OS is mentioned in the question, a HP-UX specific solutions should be fine.&lt;BR /&gt;&lt;BR /&gt;As for the solution:&lt;BR /&gt;awk -v cs="$CURRENT_STRING" -v ns="$NEW_STRING" "/$KEYWORD/ {sub(cs,ns)}&lt;BR /&gt;{print}" $file&lt;BR /&gt;&lt;BR /&gt;Between the two '/' characters no variable replacement is done, so that's why I used double instead of single quotes. Now $KEYWORD is replaced by the shell. Only problem: $KEYWORD should NOT contain slashes ("/").&lt;BR /&gt;&lt;BR /&gt;Difference between this and your script: the awk solutions (and sed) will replace, on all lines containing $KEYWORD, the first occorrence of $CURRENT_STRING, while your ed solution will only replace the first occurrence in the file.</description>
      <pubDate>Wed, 05 May 2004 07:43:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267966#M889102</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-05-05T07:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267967#M889103</link>
      <description>Many thanks about your sooner answers.&lt;BR /&gt;Suggestion from Elmar works fine but the $FILE update isn't on-line, I need a solution that replace and write into te same $FILE.&lt;BR /&gt;&lt;BR /&gt;About the $KEYWORD occurrence, never mind about; is unique!&lt;BR /&gt;&lt;BR /&gt;I'm looking for a live update of $FILE&lt;BR /&gt;&lt;BR /&gt;Rgds.</description>
      <pubDate>Wed, 05 May 2004 08:31:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267967#M889103</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2004-05-05T08:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267968#M889104</link>
      <description>You explicitly rejected perl, which can do in-file substitutions with&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e'....'&lt;BR /&gt;&lt;BR /&gt;Why reject it? It's not neccesarily obfuscated. I can also write readable perl :]&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Wed, 05 May 2004 08:38:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267968#M889104</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-05-05T08:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267969#M889105</link>
      <description>If you require chnage in place and do no want to use ed yopu can use "vi"&lt;BR /&gt;create the command file "mycom" :&lt;BR /&gt;/KEYWORD&lt;BR /&gt;:s/CURRENT_STRING/NEW_STRING/&lt;BR /&gt;:wq&lt;BR /&gt;&lt;BR /&gt;run the command :&lt;BR /&gt;vi $FILE&lt;MYCOM&gt;/dev/null&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc&lt;BR /&gt;&lt;BR /&gt;&lt;/MYCOM&gt;</description>
      <pubDate>Wed, 05 May 2004 08:43:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267969#M889105</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-05-05T08:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267970#M889106</link>
      <description>Obfuscated?  ...never!  &lt;BR /&gt;Please indicate me your suggestion in Perl&lt;BR /&gt;&lt;BR /&gt;Remember, must be a live update of $FILE!&lt;BR /&gt;&lt;BR /&gt;BRgds</description>
      <pubDate>Wed, 05 May 2004 10:36:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267970#M889106</guid>
      <dc:creator>Jose Mosquera</dc:creator>
      <dc:date>2004-05-05T10:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267971#M889107</link>
      <description># perl -pi -e'm/$ENV{KEYWORD}/o and s/$ENV{CURRENT_STRING}/$ENV{NEW_STRING}/o' $FILE&lt;BR /&gt;&lt;BR /&gt;that's all. This changes $CURRENT_STRING to $NEW_STRING only ONCE in any line that matches $KEYWORD&lt;BR /&gt;&lt;BR /&gt;If you want to play more safe, and check that the patters are on a word bound, use&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e'm/\b$ENV{KEYWORD}\b/o and s/\b$ENV{CURRENT_STRING}\b/$ENV{NEW_STRING}/o' $FILE&lt;BR /&gt;&lt;BR /&gt;and if you want to change all occurances in the matching lines&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e'm/\b$ENV{KEYWORD}\b/o and s/\b$ENV{CURRENT_STRING}\b/$ENV{NEW_STRING}/og' $FILE&lt;BR /&gt;&lt;BR /&gt;And if you want special characters in $KEYWORD and $CURRENT_STRING to match literally,&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e'm/\b\Q$ENV{KEYWORD}\E\b/o and s/\b\Q$ENV{CURRENT_STRING}\E\b/$ENV{NEW_STRING}/og' $FILE&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Wed, 05 May 2004 10:43:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267971#M889107</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-05-05T10:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267972#M889108</link>
      <description>IMHO perl is the tool of choice.&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Wed, 05 May 2004 10:48:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267972#M889108</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2004-05-05T10:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267973#M889109</link>
      <description>Jose-Maria&lt;BR /&gt;&lt;BR /&gt;You could also call awk from vi&lt;BR /&gt;&lt;BR /&gt;ex - filename &amp;lt;&amp;lt; EOF&lt;BR /&gt;1,$!awk '{ ... }'&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;Cheers &lt;BR /&gt;&lt;BR /&gt;Nicolas</description>
      <pubDate>Wed, 05 May 2004 10:50:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267973#M889109</guid>
      <dc:creator>Nicolas Dumeige</dc:creator>
      <dc:date>2004-05-05T10:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267974#M889110</link>
      <description>Your request to update directly to the file is impossible. Only a hex-editor can do direct writes to a file and do inplace changing of data.&lt;BR /&gt; &lt;BR /&gt;Any sequential file updating requires a copying of the file to a temp file, removal of the original, and renaming the temp to the original name.&lt;BR /&gt;&lt;BR /&gt;The reason of course is that any changes to a sequential text file requires possible shifting of the data.&lt;BR /&gt; &lt;BR /&gt;perl can make this process invisible, but it still will use the copy and rename process.&lt;BR /&gt; &lt;BR /&gt;my 2 cents...&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 05 May 2004 11:01:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267974#M889110</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-05-05T11:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Another way to do...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267975#M889111</link>
      <description>fwiw... All of the above solution are somewhat insecure and not one-shot. For example, they will run into trouble if the file is actively being appended.&lt;BR /&gt;&lt;BR /&gt;Just verify with ls -i&lt;BR /&gt;All the above solution will result in a new inode being used for the file.&lt;BR /&gt;&lt;BR /&gt;Direct update is possible, but is tricky and has rules to follow. Really, you can only reasonably do it if the replacement string is equal in size to the to be replaced string or if there is some slop (spaces) to play with. For sake of the argument fine below an in-place solution. Oh... it's in perl. Oops. (tested, but adatted for readability but not retested)&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;usage: perl update.pl your-file&lt;BR /&gt;&lt;BR /&gt;#--- update.pl ----&lt;BR /&gt;$file = shift or die "please provide filename";&lt;BR /&gt;open(X,"+&amp;lt;$file") or die "failed to open $file";&lt;BR /&gt;$current=tell(X)  # "=0". could leave this out.&lt;BR /&gt;while (&lt;X&gt;) {&lt;BR /&gt;  $next=tell(X);  &lt;BR /&gt;  if (/TEST/) {&lt;BR /&gt;    seek(X,$current,0);&lt;BR /&gt;    s/TEST/XXXX/;&lt;BR /&gt;    print X;&lt;BR /&gt;    seek(X,$next,0);&lt;BR /&gt;    }&lt;BR /&gt;  $current=$next;&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;----&lt;BR /&gt;So the script remembers the (byte)address for the next line to be read, then if the line is an update candidate then reseek to the start of the current line, write, and seek back to where we interrupted.&lt;BR /&gt;&lt;BR /&gt;If you know only one update is needed then you can drop the re-positions the the loop will become something like:&lt;BR /&gt;&lt;BR /&gt;while (&lt;X&gt;) { &lt;BR /&gt;  if (/KEYWORD/) {&lt;BR /&gt;    seek(X,$last,0);&lt;BR /&gt;    s/CURRENT/NEW/;&lt;BR /&gt;    print X;&lt;BR /&gt;    last;&lt;BR /&gt;    }&lt;BR /&gt;  $current=tell(X);&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;I'll leave making KEYWORD, CURRENT and NEW shell variables as an exercise to the reader :-). hint: shift from argv or read from ENV array&lt;BR /&gt;&lt;/X&gt;&lt;/X&gt;</description>
      <pubDate>Wed, 05 May 2004 14:31:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-way-to-do/m-p/3267975#M889111</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-05-05T14:31:25Z</dc:date>
    </item>
  </channel>
</rss>

