<?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: Scripting question. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626343#M40001</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Just a small little perl script I have written and tested.&lt;BR /&gt;&lt;BR /&gt;This script insert.pl takes the first column and appends the new tuple to the bottom of tuples with the same primary key, regardless of lexical or numeric order.&lt;BR /&gt;&lt;BR /&gt;insert.pl:&lt;BR /&gt;=============================&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt; &lt;BR /&gt;open (FILE, "tstfile");&lt;BR /&gt;open (NEWFILE, "&amp;gt; results");&lt;BR /&gt; &lt;BR /&gt;$reach=0;&lt;BR /&gt;$end=0;&lt;BR /&gt; &lt;BR /&gt;while (&lt;FILE&gt;)&lt;BR /&gt;{&lt;BR /&gt;  if (/^$ARGV[0] /)&lt;BR /&gt;  {&lt;BR /&gt;    $reach=1;&lt;BR /&gt;  }&lt;BR /&gt;  else&lt;BR /&gt;  {&lt;BR /&gt;    if (($reach == 1) &amp;amp;&amp;amp; ($end == 0))&lt;BR /&gt;    {&lt;BR /&gt;      $end=1;&lt;BR /&gt;      print NEWFILE "$ARGV[0] $ARGV[1]\n";&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;  print NEWFILE "$_";&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;if (($reach == 1) &amp;amp;&amp;amp; ($end == 0))&lt;BR /&gt;{&lt;BR /&gt;  $end=1;&lt;BR /&gt;  print NEWFILE "$ARGV[0] $ARGV[1]\n";&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;close (NEWFILE);&lt;BR /&gt;close (FILE);&lt;BR /&gt;`mv -f results tstfile`;&lt;BR /&gt;=============================&lt;BR /&gt;&lt;BR /&gt;Screen dump of test results:&lt;BR /&gt;=============================&lt;BR /&gt;$ cat tstfile&lt;BR /&gt;230 george &lt;BR /&gt;230 paul &lt;BR /&gt;230 mike &lt;BR /&gt;230 greg &lt;BR /&gt; &lt;BR /&gt;250 texas &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;$ ./insert.pl 230 bill&lt;BR /&gt;$ cat tstfile&lt;BR /&gt;230 george &lt;BR /&gt;230 paul &lt;BR /&gt;230 mike &lt;BR /&gt;230 greg &lt;BR /&gt;230 bill&lt;BR /&gt; &lt;BR /&gt;250 texas &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;$ ./insert.pl 250 gates&lt;BR /&gt;$ cat tstfile&lt;BR /&gt;230 george &lt;BR /&gt;230 paul &lt;BR /&gt;230 mike &lt;BR /&gt;230 greg &lt;BR /&gt;230 bill&lt;BR /&gt; &lt;BR /&gt;250 texas &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;250 gates&lt;BR /&gt;=============================&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong&lt;BR /&gt;Brainbench MVP for Unix Admin&lt;BR /&gt;&lt;A href="http://www.brainbench.com" target="_blank"&gt;http://www.brainbench.com&lt;/A&gt;&lt;/FILE&gt;</description>
    <pubDate>Thu, 06 Dec 2001 00:41:27 GMT</pubDate>
    <dc:creator>Steven Sim Kok Leong</dc:creator>
    <dc:date>2001-12-06T00:41:27Z</dc:date>
    <item>
      <title>Scripting question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626338#M39996</link>
      <description>I am writing a KSH script, and have what I hope is an easy to do thing.&lt;BR /&gt;&lt;BR /&gt;I want to add a line, but not at the end of a file, I want to add it below a section of numbers with the same number and a different variable is their a way I can do this?&lt;BR /&gt;&lt;BR /&gt;ie&lt;BR /&gt;230  george&lt;BR /&gt;230  paul&lt;BR /&gt;230  mike&lt;BR /&gt;230  greg&lt;BR /&gt;&lt;BR /&gt;250  texas&lt;BR /&gt;250  arizona&lt;BR /&gt;250  oklahoma&lt;BR /&gt;&lt;BR /&gt;I want to add 230  fred to the end of the other 230's.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Fred</description>
      <pubDate>Wed, 05 Dec 2001 21:43:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626338#M39996</guid>
      <dc:creator>Fred Myers</dc:creator>
      <dc:date>2001-12-05T21:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626339#M39997</link>
      <description>Fred, a quick way would to be simply add the string to the end of the file then pipe the  entire file through a pipe to sort -n.  &lt;BR /&gt;&lt;BR /&gt;cat filename | sort -n &amp;gt; /tmp/filename_sorted&lt;BR /&gt;&lt;BR /&gt;This will sort the file nicely based on the first numeric field of each row. This way you can throw tons of data at the file and do the sort at the very end.&lt;BR /&gt;&lt;BR /&gt;Tony&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Dec 2001 21:53:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626339#M39997</guid>
      <dc:creator>Anthony deRito</dc:creator>
      <dc:date>2001-12-05T21:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626340#M39998</link>
      <description>Anthony hits the mark right of the bat. Congrats on the new hat, also.&lt;BR /&gt;&lt;BR /&gt;One thing that sort -n will do is to sort all the data so if you want it to stay in place this may not work for you. , i.e.&lt;BR /&gt;&lt;BR /&gt;#cat tempfile | sort -n &lt;BR /&gt;230 george &lt;BR /&gt;230 greg &lt;BR /&gt;230 mike &lt;BR /&gt;230 paul &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;250 texas &lt;BR /&gt;&lt;BR /&gt;C</description>
      <pubDate>Wed, 05 Dec 2001 22:15:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626340#M39998</guid>
      <dc:creator>Craig Rants</dc:creator>
      <dc:date>2001-12-05T22:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626341#M39999</link>
      <description>Boy, you see why I don't teach english. You get this jist, your data will not be in the same order it was in prior to the sort -n.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Dec 2001 22:27:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626341#M39999</guid>
      <dc:creator>Craig Rants</dc:creator>
      <dc:date>2001-12-05T22:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626342#M40000</link>
      <description>Hi Fred,&lt;BR /&gt;&lt;BR /&gt;Anthony's is the smart way. But if you want to retain the spaces and other extra characters as they are, you can use the following...&lt;BR /&gt;&lt;BR /&gt;You can predefine NUMBER and VARIABLES in your script so that they can be used in this function like&lt;BR /&gt;&lt;BR /&gt;add_it 230 Fred&lt;BR /&gt;&lt;BR /&gt;add_it()&lt;BR /&gt;{                                              &lt;BR /&gt;NUMBER=$1                                      STRING=$2      &lt;BR /&gt;LINE=`grep "^$NUMBER" list |tail -1|awk '{print $2}'`                                           &lt;BR /&gt;sed -e '/'$NUMBER' '$LINE'/{x;s/^/'$NUMBER' '$STRING'/;x;G;}' list &lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;You may want to put other checks in this script.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Wed, 05 Dec 2001 23:16:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626342#M40000</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-12-05T23:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting question.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626343#M40001</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Just a small little perl script I have written and tested.&lt;BR /&gt;&lt;BR /&gt;This script insert.pl takes the first column and appends the new tuple to the bottom of tuples with the same primary key, regardless of lexical or numeric order.&lt;BR /&gt;&lt;BR /&gt;insert.pl:&lt;BR /&gt;=============================&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt; &lt;BR /&gt;open (FILE, "tstfile");&lt;BR /&gt;open (NEWFILE, "&amp;gt; results");&lt;BR /&gt; &lt;BR /&gt;$reach=0;&lt;BR /&gt;$end=0;&lt;BR /&gt; &lt;BR /&gt;while (&lt;FILE&gt;)&lt;BR /&gt;{&lt;BR /&gt;  if (/^$ARGV[0] /)&lt;BR /&gt;  {&lt;BR /&gt;    $reach=1;&lt;BR /&gt;  }&lt;BR /&gt;  else&lt;BR /&gt;  {&lt;BR /&gt;    if (($reach == 1) &amp;amp;&amp;amp; ($end == 0))&lt;BR /&gt;    {&lt;BR /&gt;      $end=1;&lt;BR /&gt;      print NEWFILE "$ARGV[0] $ARGV[1]\n";&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;  print NEWFILE "$_";&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;if (($reach == 1) &amp;amp;&amp;amp; ($end == 0))&lt;BR /&gt;{&lt;BR /&gt;  $end=1;&lt;BR /&gt;  print NEWFILE "$ARGV[0] $ARGV[1]\n";&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;close (NEWFILE);&lt;BR /&gt;close (FILE);&lt;BR /&gt;`mv -f results tstfile`;&lt;BR /&gt;=============================&lt;BR /&gt;&lt;BR /&gt;Screen dump of test results:&lt;BR /&gt;=============================&lt;BR /&gt;$ cat tstfile&lt;BR /&gt;230 george &lt;BR /&gt;230 paul &lt;BR /&gt;230 mike &lt;BR /&gt;230 greg &lt;BR /&gt; &lt;BR /&gt;250 texas &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;$ ./insert.pl 230 bill&lt;BR /&gt;$ cat tstfile&lt;BR /&gt;230 george &lt;BR /&gt;230 paul &lt;BR /&gt;230 mike &lt;BR /&gt;230 greg &lt;BR /&gt;230 bill&lt;BR /&gt; &lt;BR /&gt;250 texas &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;$ ./insert.pl 250 gates&lt;BR /&gt;$ cat tstfile&lt;BR /&gt;230 george &lt;BR /&gt;230 paul &lt;BR /&gt;230 mike &lt;BR /&gt;230 greg &lt;BR /&gt;230 bill&lt;BR /&gt; &lt;BR /&gt;250 texas &lt;BR /&gt;250 arizona &lt;BR /&gt;250 oklahoma &lt;BR /&gt;250 gates&lt;BR /&gt;=============================&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Regards.&lt;BR /&gt;&lt;BR /&gt;Steven Sim Kok Leong&lt;BR /&gt;Brainbench MVP for Unix Admin&lt;BR /&gt;&lt;A href="http://www.brainbench.com" target="_blank"&gt;http://www.brainbench.com&lt;/A&gt;&lt;/FILE&gt;</description>
      <pubDate>Thu, 06 Dec 2001 00:41:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-question/m-p/2626343#M40001</guid>
      <dc:creator>Steven Sim Kok Leong</dc:creator>
      <dc:date>2001-12-06T00:41:27Z</dc:date>
    </item>
  </channel>
</rss>

