<?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: ksh questions in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128573#M717752</link>
    <description>another way &lt;BR /&gt;&lt;BR /&gt;#put each field on a seperate line&lt;BR /&gt;#create a coprocess&lt;BR /&gt;print "$NEW_MPS | tr "[:space:]" "\012*" |&amp;amp;&lt;BR /&gt;&lt;BR /&gt;print "$OLD_MPS | tr "[:space:]" "\012*" |&lt;BR /&gt;while read old&lt;BR /&gt;do&lt;BR /&gt;read -p new&lt;BR /&gt;print "$old $new"&lt;BR /&gt;done</description>
    <pubDate>Tue, 25 Nov 2003 15:16:51 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2003-11-25T15:16:51Z</dc:date>
    <item>
      <title>ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128566#M717745</link>
      <description>Hpux-admins:&lt;BR /&gt;&lt;BR /&gt;I have two "variable strings" in a ksh script:&lt;BR /&gt;&lt;BR /&gt; OLD_MPS="/u1001 /u1101 /u1102 /u1201 . . . /uXYYY"&lt;BR /&gt; NEW_MPS="/u2001 /u2101 /u2102 /u2201 . . . /uZQQQ"&lt;BR /&gt;&lt;BR /&gt;I want to go through a mounted directory, and, respectively, for every occurrence of:&lt;BR /&gt; /u1001 replace it with  /u2001&lt;BR /&gt; /u1101 replace it with  /u2101&lt;BR /&gt;&lt;BR /&gt;I don't want to replace "/u1" with "/u2".  I actually want to replace the 1st occurrence in the "OLD_" list with the 1st occurrence in the "NEW_" list, the 2nd with the 2nd, the 3rd with the 3rd, etc.&lt;BR /&gt;&lt;BR /&gt;My problem is not the outside loop, but the inside:&lt;BR /&gt;&lt;BR /&gt; for OMP in $OLD_MPS&lt;BR /&gt; do&lt;BR /&gt;  echo $OMP&lt;BR /&gt;  # match with $NMP in $NEW_MPS&lt;BR /&gt;&lt;BR /&gt;Can I turn my original variable strings into arrays?  Then I could match &lt;BR /&gt;OLD_MPS[0] with NEW_MPS[0], etc.  How would I do that?&lt;BR /&gt;&lt;BR /&gt;  Stuart  &lt;BR /&gt;</description>
      <pubDate>Tue, 25 Nov 2003 14:07:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128566#M717745</guid>
      <dc:creator>Stuart Abramson_2</dc:creator>
      <dc:date>2003-11-25T14:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128567#M717746</link>
      <description>set [+/-]A name args&lt;BR /&gt;-A will cause name to be unset prior to the assignment&lt;BR /&gt;&lt;BR /&gt;set -A oldMps $OLD_MPS&lt;BR /&gt;is how to do it</description>
      <pubDate>Tue, 25 Nov 2003 14:33:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128567#M717746</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-11-25T14:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128568#M717747</link>
      <description>hopefully this won't be an issue,&lt;BR /&gt;but i believe that your limited to 1K array elements, i.e subscipts 0-1023</description>
      <pubDate>Tue, 25 Nov 2003 14:37:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128568#M717747</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-11-25T14:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128569#M717748</link>
      <description>My 'top of the head' way to do this would be the following. A little counter should solve your problem. It might not be optimal, but hey, we're just renaming directories right ?&lt;BR /&gt;&lt;BR /&gt;(note that I took the slashes out of OLD_MPS and NEW_MPS)&lt;BR /&gt;&lt;BR /&gt;----------&lt;BR /&gt;OLD_MPS="u1001 u1101 u1102 u1201" &lt;BR /&gt;NEW_MPS="u2001 u2101 u2102 u2201"&lt;BR /&gt;TARGETDIR="."&lt;BR /&gt;count=1&lt;BR /&gt;&lt;BR /&gt;for OMP in $OLD_MPS&lt;BR /&gt;do&lt;BR /&gt; NMP=`echo $NEW_MPS | cut -d " " -f$count`&lt;BR /&gt; find $TARGETDIR -type d -name $OMP -exec mv {} $NMP \; 2&amp;gt;/dev/null&lt;BR /&gt; echo $OMP to $NMP: done.&lt;BR /&gt; count=`expr $count + 1`&lt;BR /&gt;done&lt;BR /&gt;----------&lt;BR /&gt;&lt;BR /&gt;hope it helps&lt;BR /&gt;regards&lt;BR /&gt;Wouter&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Nov 2003 14:44:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128569#M717748</guid>
      <dc:creator>Wouter Jagers</dc:creator>
      <dc:date>2003-11-25T14:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128570#M717749</link>
      <description>Hi Stuart,&lt;BR /&gt;this is a simple example of reading $1 into an array:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i POS=0 i=1&lt;BR /&gt;while [ $POS -lt ${#1} ]&lt;BR /&gt;do&lt;BR /&gt;          POS=$POS+1&lt;BR /&gt;          KARAK=`echo ${1} | cut -c $POS`&lt;BR /&gt;          STRENG[$POS]="$KARAK"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;while [ $i -le $POS ]&lt;BR /&gt;do&lt;BR /&gt;        echo "${STRENG[$i]}"&lt;BR /&gt;        let i="$i+1"&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;but you of course need to take care of the "correct" number of spaces in order to e to make a sensible comparison; and use plenty of qoutes, e.g.:&lt;BR /&gt;# ./make_array.sh "/u1001 /u1101 /u1102 /u1201"&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Nov 2003 14:45:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128570#M717749</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-11-25T14:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128571#M717750</link>
      <description>Done put quotes around the array values, as in:&lt;BR /&gt;set -A oldMps "$OLD_MPS"&lt;BR /&gt;&lt;BR /&gt;you'll only get one array element&lt;BR /&gt;&lt;BR /&gt;if you more the 1K values, you could try something like this&lt;BR /&gt;&lt;BR /&gt;x=1&lt;BR /&gt;for OMP in $OLD_MPS&lt;BR /&gt;do&lt;BR /&gt;echo $OMP&lt;BR /&gt;echo $NEW_MPS | awk '{print $'$x';}'&lt;BR /&gt;x=$(( $x + 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;but i think awk is limited to about 3K fields&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Nov 2003 14:48:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128571#M717750</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-11-25T14:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128572#M717751</link>
      <description>Using a counter can also be used otherwise...&lt;BR /&gt;&lt;BR /&gt;idx=1&lt;BR /&gt;fld1=$(echo $OLD_MPS | cut -f$idx)&lt;BR /&gt;while [ -n $fld1 ]&lt;BR /&gt;do&lt;BR /&gt;   if [ -d $fld1 ]&lt;BR /&gt;   then&lt;BR /&gt;      fld2=$(echo $NEW_MPS | cut -f$idx)&lt;BR /&gt;      mv $fld1 $fld2&lt;BR /&gt;   fi&lt;BR /&gt;   idx=$(expr $idx + 1)&lt;BR /&gt;   fld1=$(echo $OLD_MPS | cut -f$idx)&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;And there is another way too, by using not OLD_MPS as the loops input, but the content of your directory... But that is too much work to do out of head.</description>
      <pubDate>Tue, 25 Nov 2003 15:01:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128572#M717751</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2003-11-25T15:01:04Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128573#M717752</link>
      <description>another way &lt;BR /&gt;&lt;BR /&gt;#put each field on a seperate line&lt;BR /&gt;#create a coprocess&lt;BR /&gt;print "$NEW_MPS | tr "[:space:]" "\012*" |&amp;amp;&lt;BR /&gt;&lt;BR /&gt;print "$OLD_MPS | tr "[:space:]" "\012*" |&lt;BR /&gt;while read old&lt;BR /&gt;do&lt;BR /&gt;read -p new&lt;BR /&gt;print "$old $new"&lt;BR /&gt;done</description>
      <pubDate>Tue, 25 Nov 2003 15:16:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128573#M717752</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-11-25T15:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: ksh questions</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128574#M717753</link>
      <description>Thanks Curt:&lt;BR /&gt;&lt;BR /&gt;Use "set -A" to turn 2 lists of corresponding values into two correspoinding arrays:&lt;BR /&gt;&lt;BR /&gt;OLD_MPS=/u1001 /u1101 /u1102 /u1201&lt;BR /&gt;NEW_MPS=/u2001 /u2101 /u2102 /u2201&lt;BR /&gt;&lt;BR /&gt;set -A OLD_ARRAY $OLD_MPS&lt;BR /&gt;set -A NEW_ARRAY $NEW_MPS&lt;BR /&gt;CNT=${#OLD_ARRAY[@]}&lt;BR /&gt;#&lt;BR /&gt;(( I=0 ))&lt;BR /&gt;while (( I &amp;lt; CNT ))&lt;BR /&gt;do&lt;BR /&gt;        echo ${OLD_ARRAY[$I]} ${NEW_ARRAY[$I]}&lt;BR /&gt;        (( I=I+1 ))&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Nov 2003 15:33:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-questions/m-p/3128574#M717753</guid>
      <dc:creator>Stuart Abramson_2</dc:creator>
      <dc:date>2003-11-25T15:33:47Z</dc:date>
    </item>
  </channel>
</rss>

