<?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: Help needed in scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398445#M863095</link>
    <description>&lt;BR /&gt;If you cat SORT the input first, then this becomes a one liner with JOIN:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ sort -k 2 x &amp;gt; a&lt;BR /&gt;$ sort -k 3 xx &amp;gt; aa&lt;BR /&gt;$ cat a&lt;BR /&gt;11      aa      22      33&lt;BR /&gt;77      bb      88      99&lt;BR /&gt;xx      cc      xx      xx&lt;BR /&gt;xx      dd      xx      xx&lt;BR /&gt;xx      gg      xx      xx&lt;BR /&gt;$ cat aa&lt;BR /&gt;44      55      aa      66&lt;BR /&gt;xx      xx      bb      xx&lt;BR /&gt;xx      xx      cc      xx&lt;BR /&gt;xx      xx      dd      xx&lt;BR /&gt;xx      xx      jj      xx&lt;BR /&gt;$ join -j1 2 -j2 3 -o 1.2 1.1 1.3 1.4 2.1 2.2 2.4 a aa&lt;BR /&gt;aa 11 22 33 44 55 66&lt;BR /&gt;bb 77 88 99 xx xx xx&lt;BR /&gt;cc xx xx xx xx xx xx&lt;BR /&gt;dd xx xx xx xx xx xx&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ join -j1 2 -j2 3 -v 1 a aa&lt;BR /&gt;gg xx xx xx&lt;BR /&gt;$ join -j1 2 -j2 3 -v 2 a aa&lt;BR /&gt;jj xx xx xx&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 12 Oct 2004 13:35:09 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2004-10-12T13:35:09Z</dc:date>
    <item>
      <title>Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398443#M863093</link>
      <description>Here is what I want to accomplish.  I've been thinking hard but I just can't get an idea on how to start the script so maybe a sample script or hint will send me on my way.&lt;BR /&gt;&lt;BR /&gt;Here is the problem.&lt;BR /&gt;&lt;BR /&gt;One file contains an ASCII table as shown below:&lt;BR /&gt;&lt;BR /&gt;file1&lt;BR /&gt;xx dd xx xx&lt;BR /&gt;11 aa 22 33&lt;BR /&gt;xx cc xx xx&lt;BR /&gt;77 bb 88 99&lt;BR /&gt;xx gg xx xx&lt;BR /&gt;&lt;BR /&gt;another file contains another ASCII table as shown below:&lt;BR /&gt;&lt;BR /&gt;file2&lt;BR /&gt;&lt;BR /&gt;xx xx cc xx&lt;BR /&gt;xx xx jj xx&lt;BR /&gt;xx xx bb xx&lt;BR /&gt;xx xx dd xx&lt;BR /&gt;44 55 aa 66&lt;BR /&gt;&lt;BR /&gt;What I want to achieve is to combine bothfiles into one table with each lines in each table combined that has the same values in the 2nd column and third columns of file1 and file2 respectively.  The unmatch data are written to another separate error logfile.  Thus the result should be:&lt;BR /&gt;&lt;BR /&gt;aa 11 22 33 44 55 66&lt;BR /&gt;bb 77 88 99 xx xx xx&lt;BR /&gt;cc xx xx xx xx xx xx&lt;BR /&gt;&lt;BR /&gt;the error log file should contain something like below:&lt;BR /&gt;&lt;BR /&gt;gg xx xx xx&lt;BR /&gt;jj xx xx xx&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for the help!</description>
      <pubDate>Tue, 12 Oct 2004 13:09:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398443#M863093</guid>
      <dc:creator>Kenneth_18</dc:creator>
      <dc:date>2004-10-12T13:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398444#M863094</link>
      <description># man join&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 12 Oct 2004 13:20:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398444#M863094</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-10-12T13:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398445#M863095</link>
      <description>&lt;BR /&gt;If you cat SORT the input first, then this becomes a one liner with JOIN:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ sort -k 2 x &amp;gt; a&lt;BR /&gt;$ sort -k 3 xx &amp;gt; aa&lt;BR /&gt;$ cat a&lt;BR /&gt;11      aa      22      33&lt;BR /&gt;77      bb      88      99&lt;BR /&gt;xx      cc      xx      xx&lt;BR /&gt;xx      dd      xx      xx&lt;BR /&gt;xx      gg      xx      xx&lt;BR /&gt;$ cat aa&lt;BR /&gt;44      55      aa      66&lt;BR /&gt;xx      xx      bb      xx&lt;BR /&gt;xx      xx      cc      xx&lt;BR /&gt;xx      xx      dd      xx&lt;BR /&gt;xx      xx      jj      xx&lt;BR /&gt;$ join -j1 2 -j2 3 -o 1.2 1.1 1.3 1.4 2.1 2.2 2.4 a aa&lt;BR /&gt;aa 11 22 33 44 55 66&lt;BR /&gt;bb 77 88 99 xx xx xx&lt;BR /&gt;cc xx xx xx xx xx xx&lt;BR /&gt;dd xx xx xx xx xx xx&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ join -j1 2 -j2 3 -v 1 a aa&lt;BR /&gt;gg xx xx xx&lt;BR /&gt;$ join -j1 2 -j2 3 -v 2 a aa&lt;BR /&gt;jj xx xx xx&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Oct 2004 13:35:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398445#M863095</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-10-12T13:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398446#M863096</link>
      <description>We can do this with sort / paste / awk as,&lt;BR /&gt;&lt;BR /&gt; sort to sort based on field 2 on file1 and filed 3 on file2&lt;BR /&gt;&lt;BR /&gt; # sort -k 2,2 file1 &amp;gt; file1.sort&lt;BR /&gt; # sort -k 3,3 file2 &amp;gt; file2.sort&lt;BR /&gt; &lt;BR /&gt; # paste -d " " file1.sort file2.sort | awk '{ print $2" "$1" "$3" "$4" "$5" "$6" "$8 }'&lt;BR /&gt;&lt;BR /&gt;aa 11 22 33 44 55 66&lt;BR /&gt;bb 77 88 99 xx xx xx&lt;BR /&gt;cc xx xx xx xx xx xx&lt;BR /&gt;dd xx xx xx xx xx xx&lt;BR /&gt;gg xx xx xx xx xx xx&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Oct 2004 14:02:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398446#M863096</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-10-12T14:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398447#M863097</link>
      <description>&lt;BR /&gt;I like the sort and join commands myself, but maybe you need to learn some perl:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;#&lt;BR /&gt;   $collected = "";&lt;BR /&gt;   $errs_collected = "";&lt;BR /&gt;#&lt;BR /&gt;   open(firstFILEPTR, "&amp;lt; ./testa") ||&lt;BR /&gt;      die "can not open ./testa for input? check your current directory permissions and space availability!";&lt;BR /&gt;   while (&lt;FIRSTFILEPTR&gt;) {&lt;BR /&gt;      chomp;&lt;BR /&gt;      ($part1,$part2,$part3,$part4) = split(/ /, $_);&lt;BR /&gt;      $collected{$part2}{"data"} = sprintf("%s %s %s %s",$part2,$part1,$part3,$part4);&lt;BR /&gt;      $collected{$part2}{"cnt"} = 4;&lt;BR /&gt;   }&lt;BR /&gt;#&lt;BR /&gt;   close (firstFILEPTR);&lt;BR /&gt;#&lt;BR /&gt;   open(secondFILEPTR, "&amp;lt; ./testb") ||&lt;BR /&gt;      die "can not open ./testb for input? check your current directory permissions and space availability!";&lt;BR /&gt;   while (&lt;SECONDFILEPTR&gt;) {&lt;BR /&gt;      chomp;&lt;BR /&gt;      ($part1,$part2,$part3,$part4) = split(/ /, $_);&lt;BR /&gt;      if ($collected{$part3} eq "") {&lt;BR /&gt;         $errs_collected{$part3} = sprintf("%s %s %s %s",$part3,$part1,$part2,$part4);&lt;BR /&gt;      } else {&lt;BR /&gt;         $collected{$part3}{"data"} = sprintf("%s %s %s %s %s",$collected{$part3}{"data"},$part1,$part2,$part4);&lt;BR /&gt;         $collected{$part3}{"cnt"} += 3;&lt;BR /&gt;      }&lt;BR /&gt;   }&lt;BR /&gt;#&lt;BR /&gt;   close (secondFILEPTR);&lt;BR /&gt;#&lt;BR /&gt;   foreach $partname ( keys %collected ) {&lt;BR /&gt;      if ($collected{$partname}{"cnt"} eq 7) {&lt;BR /&gt;         printf("%s\n",$collected{$partname}{"data"});&lt;BR /&gt;      }&lt;BR /&gt;   }&lt;BR /&gt;   printf("Errors to follow:\n");&lt;BR /&gt;   foreach $partname ( keys %collected ) {&lt;BR /&gt;      if ($collected{$partname}{"cnt"} ne 7) {&lt;BR /&gt;         printf("%s\n",$collected{$partname}{"data"});&lt;BR /&gt;      }&lt;BR /&gt;   }&lt;BR /&gt;   foreach $partname ( keys %errs_collected ) {&lt;BR /&gt;      printf("%s\n",$errs_collected{$partname});&lt;BR /&gt;   }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry&lt;/SECONDFILEPTR&gt;&lt;/FIRSTFILEPTR&gt;</description>
      <pubDate>Tue, 12 Oct 2004 14:07:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398447#M863097</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-10-12T14:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398448#M863098</link>
      <description>&lt;BR /&gt;Ooops, &lt;BR /&gt;Forgot to include my perl alternative.&lt;BR /&gt;This does not require pre-sorting and as written outputs be order of the second file argument.&lt;BR /&gt;As written it allows only 1 match per pair.&lt;BR /&gt;A perl script gives you full control over tweaks like that.&lt;BR /&gt;caveat: It sucks in the whole first file, so may become too slow for large files.&lt;BR /&gt;&lt;BR /&gt;See below.&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;$ perl x.p x xx&lt;BR /&gt;cc xx xx xx xx xx xx&lt;BR /&gt;bb 77 88 99 xx xx xx&lt;BR /&gt;dd xx xx xx xx xx xx&lt;BR /&gt;aa 11 22 33 44 55 66&lt;BR /&gt;excess from file 1&lt;BR /&gt;gg xx xx xx&lt;BR /&gt;excess from file 2&lt;BR /&gt;jj xx xx xx&lt;BR /&gt;$ cat x.p&lt;BR /&gt;$f = shift @ARGV;&lt;BR /&gt;open (F,"&amp;lt;$f") or die "Failed to open $f";&lt;BR /&gt;while (&lt;F&gt;) {&lt;BR /&gt;  chop;&lt;BR /&gt;  @w= split;&lt;BR /&gt;  $x1{$w[1]} = join(' ',$w[0], $w[2], $w[3]);&lt;BR /&gt;  }&lt;BR /&gt;close (F);&lt;BR /&gt;$f = shift @ARGV;&lt;BR /&gt;open (F,"&amp;lt;$f") or die "Failed to open $f";&lt;BR /&gt;while (&lt;F&gt;) {&lt;BR /&gt;  chop;&lt;BR /&gt;  @w= split;&lt;BR /&gt;  $j= $w[2];&lt;BR /&gt;  $f2 = join(' ',$w[0], $w[1], $w[3]);&lt;BR /&gt;  if ($f1 = $x1{$j}) {&lt;BR /&gt;    print join(' ',$j, $f1, $f2)."\n";&lt;BR /&gt;    undef $x1{$j};&lt;BR /&gt;    } else {&lt;BR /&gt;    $x2{$j} = $f2;&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;print "excess from file 1\n";&lt;BR /&gt;&lt;BR /&gt;foreach $k (keys %x1) {&lt;BR /&gt;  print "$k $x1{$k}\n" if $x1{$k};&lt;BR /&gt;  }&lt;BR /&gt;print "excess from file 2\n";&lt;BR /&gt;foreach $k (keys %x2) {&lt;BR /&gt;  print "$k $x2{$k}\n";&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;&lt;/F&gt;&lt;/F&gt;</description>
      <pubDate>Tue, 12 Oct 2004 14:39:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398448#M863098</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-10-12T14:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398449#M863099</link>
      <description>Muthukumar, Sorry but I believe your solution will only work in the example given where the 'exception' record happen to sort after the matching records. If one adds a record with key 'bc' to one of the input files the paste command will get 'out of sync'.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Oct 2004 20:02:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398449#M863099</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-10-12T20:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed in scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398450#M863100</link>
      <description>Sorry guys but I've been to busy to responed immediately.  I will try out the suggestions and let you know the results.</description>
      <pubDate>Fri, 15 Oct 2004 20:38:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-needed-in-scripting/m-p/3398450#M863100</guid>
      <dc:creator>Kenneth_18</dc:creator>
      <dc:date>2004-10-15T20:38:23Z</dc:date>
    </item>
  </channel>
</rss>

