<?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: problem with mapping two files with KSH in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029350#M747342</link>
    <description>- Does the yesno column indicate whether this was a 'new' value'&lt;BR /&gt;&lt;BR /&gt;- Is 'yesno' always N of number-of-sums is 1 and Y if more than 1?&lt;BR /&gt;&lt;BR /&gt;- Is the "N" for 323232 in the second general file a bad example?&lt;BR /&gt;323232 ; 20 ; 2 ; N &lt;BR /&gt;&lt;BR /&gt;- Do 'new' values always have to be added to the end? If now, what it the sort order? Text or numbers?&lt;BR /&gt;&lt;BR /&gt;- Is that 'KM' an option text in the sum column for the new file? Any other surprises?&lt;BR /&gt;&lt;BR /&gt;- Is the last column in new file always 1?&lt;BR /&gt;&lt;BR /&gt;- Should number-of-sums always be just incremented by one, or the last column from new added.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl example below, giving sorted output.&lt;BR /&gt;use  as : perl test.pl general new&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;--------- test.pl --------------&lt;BR /&gt;use strict;&lt;BR /&gt;my $old = shift or die "please provide general and new files";&lt;BR /&gt;my $new = shift or die "please provide new file";&lt;BR /&gt;my (%sum, %number_of_sums, %yesno);&lt;BR /&gt;&lt;BR /&gt;open OLD, "&amp;lt;$old" or die "could not open general file $old";&lt;BR /&gt;while (&lt;OLD&gt;) {&lt;BR /&gt;  next unless /^\s*\d+/;&lt;BR /&gt;  chomp;&lt;BR /&gt;  my ($id, $s, $n, $yn) = split /\s*;\s*/;&lt;BR /&gt;  $sum{$id} = $s;&lt;BR /&gt;  $number_of_sums{$id} = $n;&lt;BR /&gt;  $yesno{$id} = $yn;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;open NEW, "&amp;lt;$new" or die "could not open general file $new";&lt;BR /&gt;while (&lt;NEW&gt;) {&lt;BR /&gt;  chomp;&lt;BR /&gt;  my ($id, $s, $n, $yn) = split /\s*;\s*/;&lt;BR /&gt;  $yesno{$id} = (exists ($yesno{$id})) ? 'Y' : 'N';&lt;BR /&gt;  $s =~ s/KM//;&lt;BR /&gt;  $sum{$id} += $s;&lt;BR /&gt;  $number_of_sums{$id} += $n;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;print "id ; sum ; number-of-sums ; yesno\n\n";&lt;BR /&gt;foreach (sort keys %yesno) {&lt;BR /&gt;  print "$_ ; $sum{$_} ; $number_of_sums{$_} ; $yesno{$_}\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/NEW&gt;&lt;/OLD&gt;</description>
    <pubDate>Fri, 29 Jun 2007 08:55:48 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2007-06-29T08:55:48Z</dc:date>
    <item>
      <title>problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029349#M747341</link>
      <description>I am trying to write script that would do this scenario..in ksh&lt;BR /&gt;&lt;BR /&gt;and FS is ; in both files.&lt;BR /&gt;&lt;BR /&gt;general.txt:&lt;BR /&gt;&lt;BR /&gt;323232 ;  10  ;      1       ; N&lt;BR /&gt;777777 ;  10  ;      2       ; N&lt;BR /&gt;989898 ;  10  ;      4       ; N&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;new file comes with values:&lt;BR /&gt;&lt;BR /&gt;newfile.txt&lt;BR /&gt;&lt;BR /&gt;323232 ; 10 ; 1 &lt;BR /&gt;777777 ; 20 ; 1&lt;BR /&gt;989898 ; 40 ; 1&lt;BR /&gt;&lt;BR /&gt;then general.txt should look like:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;***** general file: ****&lt;BR /&gt;id      ; sum ; number-of-sums ; yesno&lt;BR /&gt;&lt;BR /&gt;323232 ;  20  ;      2       ; N&lt;BR /&gt;777777 ;  30  ;      3       ; Y&lt;BR /&gt;989898 ;  50  ;      5       ; Y&lt;BR /&gt;&lt;BR /&gt;here comes more scenarios on new files that comes and should change general.txt files&lt;BR /&gt;___________________________________________&lt;BR /&gt;&lt;BR /&gt;new file comes with values:&lt;BR /&gt;&lt;BR /&gt;new file:&lt;BR /&gt;323232 ; 10 ; 1 &lt;BR /&gt;777777 ; 10 ; 1&lt;BR /&gt;989898 ; 10 ; 1&lt;BR /&gt;656565 ; 10 ; 1&lt;BR /&gt;&lt;BR /&gt;***** general file: ****&lt;BR /&gt;id      ; sum ; number-of-sums ; yesno&lt;BR /&gt;&lt;BR /&gt;323232 ;  30  ;      3       ; Y&lt;BR /&gt;777777 ;  40  ;      4       ; Y&lt;BR /&gt;989898 ;  60  ;      6       ; Y&lt;BR /&gt;656565 ;  10  ;      1       ; N&lt;BR /&gt;&lt;BR /&gt;___________________________________________&lt;BR /&gt;&lt;BR /&gt;new file comes with values:&lt;BR /&gt;&lt;BR /&gt;new file:&lt;BR /&gt;323232 ; 10KM ; 1 &lt;BR /&gt;777777 ; 10KM ; 1&lt;BR /&gt;989898 ; 20KM ; 1&lt;BR /&gt;909099 ; 20KM ; 1&lt;BR /&gt;&lt;BR /&gt;***** general file: ****&lt;BR /&gt;id      ; sum ; number-of-sums ; yesno&lt;BR /&gt;&lt;BR /&gt;323232 ;  40  ;      4       ; Y&lt;BR /&gt;777777 ;  50  ;      5       ; Y&lt;BR /&gt;989898 ;  80  ;      7       ; Y&lt;BR /&gt;656565 ;  10  ;      1       ; N&lt;BR /&gt;909099 ;  20  ;      1       ; N&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;___________________________________________&lt;BR /&gt;&lt;BR /&gt;new file comes with values:&lt;BR /&gt;&lt;BR /&gt;new file:&lt;BR /&gt;656565 ; 10 ; 1 &lt;BR /&gt;380000 ; 10 ; 1&lt;BR /&gt;656565 ; 50 ; 1&lt;BR /&gt;909099 ; 20 ; 1&lt;BR /&gt;&lt;BR /&gt;***** general file: ****&lt;BR /&gt;&lt;BR /&gt;id      ; sum ; number-of-sums ; yesno&lt;BR /&gt;323232 ;  40  ;      4       ; Y&lt;BR /&gt;777777 ;  50  ;      5       ; Y&lt;BR /&gt;989898 ;  80  ;      7       ; Y&lt;BR /&gt;656565 ;  70  ;      3       ; Y&lt;BR /&gt;909099 ;  40  ;      2       ; Y&lt;BR /&gt;380000 ;  10  ;      1       ; N</description>
      <pubDate>Fri, 29 Jun 2007 08:01:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029349#M747341</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2007-06-29T08:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029350#M747342</link>
      <description>- Does the yesno column indicate whether this was a 'new' value'&lt;BR /&gt;&lt;BR /&gt;- Is 'yesno' always N of number-of-sums is 1 and Y if more than 1?&lt;BR /&gt;&lt;BR /&gt;- Is the "N" for 323232 in the second general file a bad example?&lt;BR /&gt;323232 ; 20 ; 2 ; N &lt;BR /&gt;&lt;BR /&gt;- Do 'new' values always have to be added to the end? If now, what it the sort order? Text or numbers?&lt;BR /&gt;&lt;BR /&gt;- Is that 'KM' an option text in the sum column for the new file? Any other surprises?&lt;BR /&gt;&lt;BR /&gt;- Is the last column in new file always 1?&lt;BR /&gt;&lt;BR /&gt;- Should number-of-sums always be just incremented by one, or the last column from new added.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl example below, giving sorted output.&lt;BR /&gt;use  as : perl test.pl general new&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;--------- test.pl --------------&lt;BR /&gt;use strict;&lt;BR /&gt;my $old = shift or die "please provide general and new files";&lt;BR /&gt;my $new = shift or die "please provide new file";&lt;BR /&gt;my (%sum, %number_of_sums, %yesno);&lt;BR /&gt;&lt;BR /&gt;open OLD, "&amp;lt;$old" or die "could not open general file $old";&lt;BR /&gt;while (&lt;OLD&gt;) {&lt;BR /&gt;  next unless /^\s*\d+/;&lt;BR /&gt;  chomp;&lt;BR /&gt;  my ($id, $s, $n, $yn) = split /\s*;\s*/;&lt;BR /&gt;  $sum{$id} = $s;&lt;BR /&gt;  $number_of_sums{$id} = $n;&lt;BR /&gt;  $yesno{$id} = $yn;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;open NEW, "&amp;lt;$new" or die "could not open general file $new";&lt;BR /&gt;while (&lt;NEW&gt;) {&lt;BR /&gt;  chomp;&lt;BR /&gt;  my ($id, $s, $n, $yn) = split /\s*;\s*/;&lt;BR /&gt;  $yesno{$id} = (exists ($yesno{$id})) ? 'Y' : 'N';&lt;BR /&gt;  $s =~ s/KM//;&lt;BR /&gt;  $sum{$id} += $s;&lt;BR /&gt;  $number_of_sums{$id} += $n;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;print "id ; sum ; number-of-sums ; yesno\n\n";&lt;BR /&gt;foreach (sort keys %yesno) {&lt;BR /&gt;  print "$_ ; $sum{$_} ; $number_of_sums{$_} ; $yesno{$_}\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/NEW&gt;&lt;/OLD&gt;</description>
      <pubDate>Fri, 29 Jun 2007 08:55:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029350#M747342</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-06-29T08:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029351#M747343</link>
      <description>&lt;BR /&gt;Here is a ksh-script:&lt;BR /&gt;It will only work, if the new files have just numbers in column 2 and 3.&lt;BR /&gt;The filename of the newfile has to be $1.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;GEN_FILE=./general.txt&lt;BR /&gt;NEW_FILE=${1}&lt;BR /&gt;&lt;BR /&gt;typeset -i mySUM=0&lt;BR /&gt;typeset -i myNOS=0&lt;BR /&gt;typeset -i newSUM=0&lt;BR /&gt;typeset -i newNOS=0&lt;BR /&gt;typeset -i valSUM=0&lt;BR /&gt;typeset -i valNOS=0&lt;BR /&gt;&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;newID=`echo $line | awk 'BEGIN { FS=" ; " } { print $1 }'`&lt;BR /&gt;newSUM=`echo $line | awk 'BEGIN { FS=" ; " } { print $2 }'`&lt;BR /&gt;newNOS=`echo $line | awk 'BEGIN { FS=" ; " } { print $3 }'`&lt;BR /&gt;&lt;BR /&gt;grep "${newID}" ${GEN_FILE} &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;BR /&gt;if [[ $? -ne 0 ]]&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt;echo "${newID} ; ${newSUM} ; ${newNOS} ; N" &amp;gt;&amp;gt; ${GEN_FILE}&lt;BR /&gt;&lt;BR /&gt;else&lt;BR /&gt;&lt;BR /&gt;mySUM=`grep $newID ./general.txt | awk 'BEGIN { FS="; " } { print $2 }'`&lt;BR /&gt;myNOS=`grep $newID ./general.txt | awk 'BEGIN { FS="; " } { print $3 }'`&lt;BR /&gt;&lt;BR /&gt;let valSUM=${mySUM}+${newSUM}&lt;BR /&gt;let valNOS=${myNOS}+${newNOS}&lt;BR /&gt;&lt;BR /&gt;if [[ ${valNOS} &amp;gt; 2 ]]&lt;BR /&gt;then&lt;BR /&gt; newYN="Y"&lt;BR /&gt;else&lt;BR /&gt; newYN="N"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;grep -v ${newID} ${GEN_FILE} &amp;gt; ${GEN_FILE}_new&lt;BR /&gt;&lt;BR /&gt;echo "${newID} ; ${valSUM} ; ${valNOS} ; ${newYN}" &amp;gt;&amp;gt; ${GEN_FILE}_new&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;mv ${GEN_FILE}_new ${GEN_FILE}&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; ${NEW_FILE}&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Jun 2007 10:43:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029351#M747343</guid>
      <dc:creator>Dino_4</dc:creator>
      <dc:date>2007-06-29T10:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029352#M747344</link>
      <description>That could work Dino, as long as you don't mind the new lines earliy in the general files. And as long as there was not thousands of lines as the files will eb read thousands of times. And are you sure you get the old lines from general which did not have a new line?&lt;BR /&gt;&lt;BR /&gt;Detail comment&amp;gt;&amp;gt;&amp;gt; mySUM=`grep $newID ./general.txt | awk 'BEGIN { FS="; " } { print $2 }'`&lt;BR /&gt;&lt;BR /&gt;Why not let awk also do the match?&lt;BR /&gt;Like:&lt;BR /&gt;&lt;BR /&gt;mySUM=$(awk -F';' '/'$newID'/{ print $2 }' $GEN_FILE)&lt;BR /&gt;&lt;BR /&gt;Hein&lt;BR /&gt;&lt;BR /&gt;---- perl variant leaving old general order in place ----&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;my $old = shift or die "please provide general and new files";&lt;BR /&gt;my $new = shift or die "please provide new file";&lt;BR /&gt;my (%sum, %number_of_sums);&lt;BR /&gt;my ($id, $s, $n, $yn);&lt;BR /&gt;&lt;BR /&gt;open NEW, "&amp;lt;$new" or die "could not open general file $new";&lt;BR /&gt;while (&lt;NEW&gt;) {&lt;BR /&gt;  chomp;&lt;BR /&gt;  ($id, $s, $n) = split /\s*;\s*/;&lt;BR /&gt;  $s =~ s/KM//;&lt;BR /&gt;  $sum{$id} += $s;&lt;BR /&gt;  $number_of_sums{$id} += $n;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;open OLD, "&amp;lt;$old" or die "could not open general file $old";&lt;BR /&gt;while (&lt;OLD&gt;) {&lt;BR /&gt;  if (/^\s*(\d+)\s*;/) {&lt;BR /&gt;    if (exists ($sum{$1})) {&lt;BR /&gt;       ($id, $s, $n, $yn) = split /\s*;\s*/;&lt;BR /&gt;       $s += $sum{$id};&lt;BR /&gt;       $n += $number_of_sums{$id};&lt;BR /&gt;       $yn = "Y";&lt;BR /&gt;       delete $sum{$id};&lt;BR /&gt;    }&lt;BR /&gt;    $_ = "$id ; $s ; $n ; $yn\n";&lt;BR /&gt;  }&lt;BR /&gt;  print;&lt;BR /&gt;}&lt;BR /&gt;foreach $id (keys %sum) {&lt;BR /&gt;  print "$id ; $sum{$id} ; $number_of_sums{$id} ; N\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;/OLD&gt;&lt;/NEW&gt;</description>
      <pubDate>Fri, 29 Jun 2007 11:06:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029352#M747344</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-06-29T11:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029353#M747345</link>
      <description>&lt;BR /&gt;Hi Hein,&lt;BR /&gt;&lt;BR /&gt;you are right.&lt;BR /&gt;I didn't think of sorting because once it has a certain size you have to grep for the needed information anyway, I guess.&lt;BR /&gt;&lt;BR /&gt;Btw: Let AWK do the work of mathing is very neat. Didn't thought about that. :-(</description>
      <pubDate>Fri, 29 Jun 2007 11:13:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029353#M747345</guid>
      <dc:creator>Dino_4</dc:creator>
      <dc:date>2007-06-29T11:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029354#M747346</link>
      <description>Yes thanks but I have no clue about perl..and I do not have perl copiler..I forgot to mention that.&lt;BR /&gt;&lt;BR /&gt;here are some answers to your Q.&lt;BR /&gt;&lt;BR /&gt;Q Does the yesno column indicate whether this was a 'new' value'&lt;BR /&gt;&lt;BR /&gt;A if second field is greater then 30 then 4th field should be Y.&lt;BR /&gt;&lt;BR /&gt;Q - Is 'yesno' always N of number-of-sums is 1 and Y if more than 1?&lt;BR /&gt;&lt;BR /&gt;number of sums is not thet much releveant field..it can be number od sums 2 and YN flag can be N. for example if value in general.txt is 10 and value in newfile.txt is 10 (10+10 = 20 that is lower then 30 so flag is N)&lt;BR /&gt;&lt;BR /&gt;Q &lt;BR /&gt;- Is the "N" for 323232 in the second general file a bad example?&lt;BR /&gt;323232 ; 20 ; 2 ; N &lt;BR /&gt;&lt;BR /&gt;No it is not bad example as U can see in seconf field it stands 20 (lower then 30)&lt;BR /&gt;&lt;BR /&gt;Q - Do 'new' values always have to be added to the end? If now, what it the sort order? Text or numbers?&lt;BR /&gt;&lt;BR /&gt;new values are added thru new txt file and two files are mapping as I explaind better in post #1.&lt;BR /&gt;&lt;BR /&gt;Q &lt;BR /&gt;- Is that 'KM' an option text in the sum column for the new file? Any other surprises?&lt;BR /&gt;&lt;BR /&gt;forgot the KM it is misstake it should not be there..&lt;BR /&gt;&lt;BR /&gt;Q - Is the last column in new file always 1?&lt;BR /&gt;&lt;BR /&gt;Yes it is always 1..(I hope so..:()&lt;BR /&gt;&lt;BR /&gt;Q - Should number-of-sums always be just incremented by one, or the last column from new added. &lt;BR /&gt;&lt;BR /&gt;well it should be incremented by one if value in newfile last filed is one&lt;BR /&gt;&lt;BR /&gt;if new file is:&lt;BR /&gt;new file:&lt;BR /&gt;656565 ; 10 ; 1 &lt;BR /&gt;380000 ; 10 ; 1&lt;BR /&gt;656565 ; 50 ; 1&lt;BR /&gt;909099 ; 20 ; 1&lt;BR /&gt;&lt;BR /&gt;then it should be incremented by 1.&lt;BR /&gt;&lt;BR /&gt;thanks and I would appreciate any solution in KSH.&lt;BR /&gt;&lt;BR /&gt;regards&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Jul 2007 00:47:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029354#M747346</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2007-07-02T00:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: problem with mapping two files with KSH</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029355#M747347</link>
      <description>thanks dino..I think this is what I wanted..I works..&lt;BR /&gt;&lt;BR /&gt;regards.&lt;BR /&gt;thanks everyone!!!</description>
      <pubDate>Mon, 02 Jul 2007 00:59:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/problem-with-mapping-two-files-with-ksh/m-p/4029355#M747347</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2007-07-02T00:59:45Z</dc:date>
    </item>
  </channel>
</rss>

