<?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 problem. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805235#M720778</link>
    <description>Well we found out that there were other issues with the data, and this script is no longer needed.  &lt;BR /&gt;&lt;BR /&gt;I didn't get a chance to test all of your solutions, so everyone gets 8 points for their efforts.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the help.&lt;BR /&gt;&lt;BR /&gt;Sean&lt;BR /&gt;</description>
    <pubDate>Thu, 19 Sep 2002 14:07:43 GMT</pubDate>
    <dc:creator>Sean OB_1</dc:creator>
    <dc:date>2002-09-19T14:07:43Z</dc:date>
    <item>
      <title>Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805225#M720768</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;I have a scripting problem I need some help with.  &lt;BR /&gt;&lt;BR /&gt;I need to take a file and sort through it and remove records with a duplicate key field.  That part is easy, however the hard part is that I need to remove a particular record based on what another field is.&lt;BR /&gt;&lt;BR /&gt;Here is a sample input file:&lt;BR /&gt;&lt;BR /&gt;2443:oliveira:jacquelyn:f:424225:employee:234:ef4442&lt;BR /&gt;3465:garvey:thomas:j:554322:employee:235:ef4422&lt;BR /&gt;4135:swan:monroe::314642:employee:245:sw4443&lt;BR /&gt;4135:swan:monroe::314642:student:245:sf4345&lt;BR /&gt;1244:praxel:lynn:m:652424:employee:243:ef4432&lt;BR /&gt;1244:praxel:lynn:m:652424:student:243:sf4432&lt;BR /&gt;7665:anderson:thomas:j:554322:student:265:sf4422&lt;BR /&gt;&lt;BR /&gt;In this file there are two duplicate people:  Swan, and Praxel.  I need to keep the employee record if the last field doesn't start with sw.&lt;BR /&gt;&lt;BR /&gt;However if the last field starts with sw, then I need to keep the student record.&lt;BR /&gt;&lt;BR /&gt;So for the above, this is the resulting file I need:&lt;BR /&gt;&lt;BR /&gt;2443:oliveira:jacquelyn:f:424225:employee:234:ef4442&lt;BR /&gt;3465:garvey:thomas:j:554322:employee:235:ef4422&lt;BR /&gt;4135:swan:monroe::314642:student:245:sf4345&lt;BR /&gt;1244:praxel:lynn:m:652424:employee:243:ef4432&lt;BR /&gt;7665:anderson:thomas:j:554322:student:265:sf4422&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;TIA,&lt;BR /&gt;&lt;BR /&gt;Sean</description>
      <pubDate>Thu, 12 Sep 2002 15:22:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805225#M720768</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-12T15:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805226#M720769</link>
      <description>awk -F: '{if (match($NF,"^sw") == 0) print}' &amp;lt; file</description>
      <pubDate>Thu, 12 Sep 2002 15:44:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805226#M720769</guid>
      <dc:creator>George A Bodnar</dc:creator>
      <dc:date>2002-09-12T15:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805227#M720770</link>
      <description>Here is a simple perl script. It will display only unique id's, unless it is a "sw" type, then it will display that entry.&lt;BR /&gt;&lt;BR /&gt;open(INP,"&lt;YOURDATA&gt;&lt;/YOURDATA&gt;while(&lt;INP&gt;) {&lt;BR /&gt; chomp;&lt;BR /&gt; @a=split(":",$_);&lt;BR /&gt; $code=substr($a[7],0,2);&lt;BR /&gt; $ix=$code eq "sw" ? 1 : 0;&lt;BR /&gt; $hold{$a[0]}[$ix]=$_;&lt;BR /&gt;}&lt;BR /&gt;foreach $nbr (sort keys %hold) {&lt;BR /&gt; if ($rec=$hold{$nbr}[1]) { print $rec,"\n"; }&lt;BR /&gt; else                     { print $hold{$nbr}[0],"\n"; }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills&lt;/INP&gt;</description>
      <pubDate>Thu, 12 Sep 2002 15:49:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805227#M720770</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-09-12T15:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805228#M720771</link>
      <description>l1:/tmp 177 &amp;gt; cat xx.txt&lt;BR /&gt;2443:oliveira:jacquelyn:f:424225:employee:234:ef4442&lt;BR /&gt;3465:garvey:thomas:j:554322:employee:235:ef4422&lt;BR /&gt;4135:swan:monroe::314642:employee:245:sw4443&lt;BR /&gt;4135:swan:monroe::314642:student:245:sf4345&lt;BR /&gt;1244:praxel:lynn:m:652424:employee:243:ef4432&lt;BR /&gt;1244:praxel:lynn:m:652424:student:243:sf4432&lt;BR /&gt;7665:anderson:thomas:j:554322:student:265:sf4422&lt;BR /&gt;l1:/tmp 178 &amp;gt; perl -naF: -e'push@{$e{$F[1]}},[@F]}END{$,=":";for(keys%e){@x=@{$e{$_}};@x&amp;gt;1 and@x=grep{$_-&amp;gt;[-1]!~/^sw/}@x;@x&amp;gt;1 and@x=grep{$_-&amp;gt;[-3]=~/^e/}@x;print@$_ for@x}' xx.txt&lt;BR /&gt;3465:garvey:thomas:j:554322:employee:235:ef4422&lt;BR /&gt;4135:swan:monroe::314642:student:245:sf4345&lt;BR /&gt;1244:praxel:lynn:m:652424:employee:243:ef4432&lt;BR /&gt;7665:anderson:thomas:j:554322:student:265:sf4422&lt;BR /&gt;2443:oliveira:jacquelyn:f:424225:employee:234:ef4442&lt;BR /&gt;l1:/tmp 179 &amp;gt;</description>
      <pubDate>Thu, 12 Sep 2002 15:49:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805228#M720771</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-09-12T15:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805229#M720772</link>
      <description>If you want a one-liner, how about-&lt;BR /&gt;&lt;BR /&gt;perl -naF: -e '{next if $t{$F[0]} eq "sw";$h{$F[0]}=$_;$t{$F[0]=substr($F[7],0,2)}END{print values %h}'&lt;BR /&gt;&lt;BR /&gt;This collects each record into $h{} keys on id number (1st field) until a "sw" is found, then no more is collected on the id number. The output will not be in any sorted order.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 12 Sep 2002 16:08:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805229#M720772</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-09-12T16:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805230#M720773</link>
      <description>&lt;BR /&gt;What do you want to do when the ONLY record has in the last field a string that starts with "sw" ?? Like if the following record was in the file (NO duplicate):&lt;BR /&gt;&lt;BR /&gt;4465:duck:donald::884712:student:239:sw6969 &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 12 Sep 2002 16:35:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805230#M720773</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-09-12T16:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805231#M720774</link>
      <description>Rodney, I thought he wanted to use $F[1] as key, but maybe I'm reading it wrong&lt;BR /&gt;Harry, my solution already catches that&lt;BR /&gt;&lt;BR /&gt;If for field [1] (the name) there is only one record, print it. If there is more than one, filter out the records where the last field starts with sw. If there still more than one record for that key, use the employee one.&lt;BR /&gt;&lt;BR /&gt;which yielded what he wanted&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Sep 2002 16:40:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805231#M720774</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-09-12T16:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805232#M720775</link>
      <description>Slight change to Rodney's one-liner:&lt;BR /&gt;&lt;BR /&gt;perl -naF: -e '{&lt;BR /&gt;next if defined($t{$F[0]}) &amp;amp;&amp;amp; $t{$F[0]} ne "sw";&lt;BR /&gt;$h{$F[0]}=$_;&lt;BR /&gt;$t{$F[0]}=substr($F[7],0,2);&lt;BR /&gt;}&lt;BR /&gt;END{print values %h}'&lt;BR /&gt;&lt;BR /&gt;Tom</description>
      <pubDate>Thu, 12 Sep 2002 16:58:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805232#M720775</guid>
      <dc:creator>Tom Maloy</dc:creator>
      <dc:date>2002-09-12T16:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805233#M720776</link>
      <description>Harry,&lt;BR /&gt;&lt;BR /&gt;In theory there should NEVER be only a record with a sw field.&lt;BR /&gt;&lt;BR /&gt;But in any case if there is only one record for the ID, then that record needs to be kept.&lt;BR /&gt;&lt;BR /&gt;The basis of this is a student file and an employee file being combined into a unique file.&lt;BR /&gt;&lt;BR /&gt;It is possible that a person could be an actual employee and student, in which case we want the employee record.  It's also possible that a person could be a student and student worker (employee) in which case we want the student record.&lt;BR /&gt;&lt;BR /&gt;Anyone in only one of the two files should be kept.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Sep 2002 16:58:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805233#M720776</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-12T16:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805234#M720777</link>
      <description>Harry,&lt;BR /&gt;&lt;BR /&gt;Both of my solutions handle that situtation. It grabs whatever records are available into a hash variable and then dumps out what was collected (minus duplicates and keeping "sw" even if it the only record for that id).&lt;BR /&gt;&lt;BR /&gt;Syntax fix to my previous one liner-&lt;BR /&gt;perl -naF: -e '{next if $t{$F[0]} eq "sw";$h{$F[0]}=$_;$t{$F[0]}=substr($F[7],0,2)}END{print values %h}' xx.txt&lt;BR /&gt;&lt;BR /&gt;(forgot a closing '}')...&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 12 Sep 2002 17:00:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805234#M720777</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-09-12T17:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting problem.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805235#M720778</link>
      <description>Well we found out that there were other issues with the data, and this script is no longer needed.  &lt;BR /&gt;&lt;BR /&gt;I didn't get a chance to test all of your solutions, so everyone gets 8 points for their efforts.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the help.&lt;BR /&gt;&lt;BR /&gt;Sean&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Sep 2002 14:07:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-problem/m-p/2805235#M720778</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2002-09-19T14:07:43Z</dc:date>
    </item>
  </channel>
</rss>

