<?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: Echo and foreach loop problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479755#M847458</link>
    <description>Hi All,&lt;BR /&gt;I manage to get it works now. As advised by Hein, I cut and paste the script from here and it works now.&lt;BR /&gt;&lt;BR /&gt;Thanks  a lot.&lt;BR /&gt;You guys are really great!</description>
    <pubDate>Mon, 14 Feb 2005 03:03:26 GMT</pubDate>
    <dc:creator>Aminur Rizal</dc:creator>
    <dc:date>2005-02-14T03:03:26Z</dc:date>
    <item>
      <title>Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479744#M847447</link>
      <description>Hi all,&lt;BR /&gt;I have the following script&lt;BR /&gt;&lt;BR /&gt;#!/bin/csh&lt;BR /&gt;set imsi=`grep IMSI test.out | awk '{print $3}'`&lt;BR /&gt;foreach ki (sed -n 'var_out/,p' test.out | sed '1,2d' | awk '{print $7}'`)&lt;BR /&gt;echo "ZMAC:IMSI=${imsi}":KI="$ki",UV=50"&lt;BR /&gt;end&lt;BR /&gt;&lt;BR /&gt;The first line while produce&lt;BR /&gt;imsi1&lt;BR /&gt;&lt;BR /&gt; and&lt;BR /&gt;for 2nd line will produde :=&lt;BR /&gt;ki1&lt;BR /&gt;ki2&lt;BR /&gt;ki3&lt;BR /&gt;ki4&lt;BR /&gt;&lt;BR /&gt;and i was try to get the output using echo as :=&lt;BR /&gt;ZMAC:IMSI=imsi1":KI=ki1,UV=50;&lt;BR /&gt;ZMAC:IMSI=imsi1":KI=ki2,UV=50;&lt;BR /&gt;ZMAC:IMSI=imsi1":KI=ki3,UV=50;&lt;BR /&gt;&lt;BR /&gt;But the above script only give me :=&lt;BR /&gt;:KI=ki1,UV=50;&lt;BR /&gt;:KI=ki2,UV=50;&lt;BR /&gt;:KI=ki3,UV=50;&lt;BR /&gt;with the missing 1st parameter.&lt;BR /&gt;Where did i go wrong?&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;You guys are great!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Feb 2005 05:03:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479744#M847447</guid>
      <dc:creator>Aminur Rizal</dc:creator>
      <dc:date>2005-02-07T05:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479745#M847448</link>
      <description>hi, &lt;BR /&gt; &lt;BR /&gt;too many quotes&lt;BR /&gt;try&lt;BR /&gt;echo "ZMAC:IMSI=${imsi}:KI=${ki},UV=50"&lt;BR /&gt;instead of&lt;BR /&gt;echo "ZMAC:IMSI=${imsi}":KI="$ki",UV=50"&lt;BR /&gt;  &lt;BR /&gt;regards,&lt;BR /&gt;Thierry</description>
      <pubDate>Mon, 07 Feb 2005 05:39:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479745#M847448</guid>
      <dc:creator>Thierry Poels_1</dc:creator>
      <dc:date>2005-02-07T05:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479746#M847449</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Or you can use:&lt;BR /&gt;&lt;BR /&gt;echo "ZMAC:IMSI="${imsi}":KI="$ki",UV=50"&lt;BR /&gt;&lt;BR /&gt;to create new subscribers.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Bob</description>
      <pubDate>Mon, 07 Feb 2005 07:13:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479746#M847449</guid>
      <dc:creator>B. Hulst</dc:creator>
      <dc:date>2005-02-07T07:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479747#M847450</link>
      <description>Hi,&lt;BR /&gt;Thanks but both of the solution seems not working for me.&lt;BR /&gt;The output is still &lt;BR /&gt;:KI=ki1,UV=50;&lt;BR /&gt;:KI=ki2,UV=50;&lt;BR /&gt;:KI=ki3,UV=50;&lt;BR /&gt;&lt;BR /&gt;Hmm..&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Feb 2005 21:31:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479747#M847450</guid>
      <dc:creator>Aminur Rizal</dc:creator>
      <dc:date>2005-02-07T21:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479748#M847451</link>
      <description>There appear to be some typo's in you script.&lt;BR /&gt;Please do not retype... just cut &amp;amp; paste!&lt;BR /&gt;It would help to have a small 'test.out' attache to try on.&lt;BR /&gt;&lt;BR /&gt;This works on my SuSe 9 box:&lt;BR /&gt;&lt;BR /&gt;#!/bin/csh&lt;BR /&gt;set imsi=`grep IMSI test.out | awk '{print $3}'`&lt;BR /&gt;foreach ki (`sed -n "/var_out/p" test.out | sed "1,2d" | awk '{print $7}'`)&lt;BR /&gt;echo "ZMAC:IMSI=${imsi}":KI="$ki",UV=50&lt;BR /&gt;end&lt;BR /&gt;&lt;BR /&gt;----- input ----&lt;BR /&gt;&lt;BR /&gt;IMSI xxx imsi1&lt;BR /&gt;a var_out c d e f ki5 x x&lt;BR /&gt;a var_out c d e f ki6 x x&lt;BR /&gt;a var_out c d e f ki7 x x&lt;BR /&gt;a var_out c d e f ki8 x x&lt;BR /&gt;&lt;BR /&gt;a b c d e f ki1 x x&lt;BR /&gt;a var_out c d e f ki2 x x&lt;BR /&gt;a b var_out d e f ki3 x x&lt;BR /&gt;a b c var_out e f ki4 x x&lt;BR /&gt;a b c d e f ki5 x x&lt;BR /&gt;&lt;BR /&gt;------ output -------&lt;BR /&gt;ZMAC:IMSI=imsi1:KI=ki7,UV=50&lt;BR /&gt;ZMAC:IMSI=imsi1:KI=ki8,UV=50&lt;BR /&gt;ZMAC:IMSI=imsi1:KI=ki2,UV=50&lt;BR /&gt;ZMAC:IMSI=imsi1:KI=ki3,UV=50&lt;BR /&gt;ZMAC:IMSI=imsi1:KI=ki4,UV=50&lt;BR /&gt;&lt;BR /&gt;The following perl 'one-liner' gives the same output. The only assumption is the the line with IMSI comes before var_out. Does it?&lt;BR /&gt;&lt;BR /&gt;perl -ne '$imsi=(split)[2] if /IMSI/; print "ZMAC:IMSI=${imsi}:KI=".(split)[6].",UV=50\n" if (/var_out/ &amp;amp;&amp;amp; ($i++ &amp;gt; 1))' est.out&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 08 Feb 2005 00:10:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479748#M847451</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-08T00:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479749#M847452</link>
      <description>Hi Hein,&lt;BR /&gt;This is a sample of test.out&lt;BR /&gt;&lt;BR /&gt;----------&lt;BR /&gt;Transport_key: 2&lt;BR /&gt;A3_Type: 04&lt;BR /&gt;PPD_srn :&lt;BR /&gt;Quantity: 80&lt;BR /&gt;Type: Plug-in&lt;BR /&gt;Profile:&lt;BR /&gt;Batch: SIMT101&lt;BR /&gt;SIM_Reference: USIM_TEST&lt;BR /&gt;HLR: 1&lt;BR /&gt;Location: WM&lt;BR /&gt;013/019: 013&lt;BR /&gt;Graph_ref: &lt;BR /&gt;var_in_list:&lt;BR /&gt;Ser_nb: 896017363050170155364&lt;BR /&gt;IMSI  : 5021313872800000096&lt;BR /&gt;&lt;BR /&gt;var_out: PUK/PIN/PIN2/PUK2/KI/ADM1&lt;BR /&gt;&lt;BR /&gt;8960130501701553643F 502131300000096 11111111 1234 1234 22222222 11111111111111111111111111111111 12345678&lt;BR /&gt;8960130501701553650F 502131300000097 11111111 1234 1234 22222222 11111111111111111111111111111111 12345678&lt;BR /&gt;8960130501701553668F 502131300000098 11111111 1234 1234 22222222 11111111111111111111111111111111 12345678&lt;BR /&gt;-------------------------------&lt;BR /&gt;&lt;BR /&gt;I have tried with this&lt;BR /&gt;#!/bin/csh&lt;BR /&gt;set imsi=`grep IMSI test.out | awk '{print $3}'`&lt;BR /&gt;foreach ki (sed -n 'var_out/,p' test.out | sed '1,2d' | awk '{print $7}'`)&lt;BR /&gt;echo "ZMAC:IMSI=${imsi}:KI=$ki,UV=50"&lt;BR /&gt;end&lt;BR /&gt;------------------&lt;BR /&gt;But the result was half of the command in multiple line - first half missing.&lt;BR /&gt;&lt;BR /&gt;:KI=11111111111111111111111111111111,UV=50&lt;BR /&gt;:KI=11111111111111111111111111111111,UV=50&lt;BR /&gt;:KI=11111111111111111111111111111111,UV=50&lt;BR /&gt;:KI=11111111111111111111111111111111,UV=50&lt;BR /&gt;:KI=11111111111111111111111111111111,UV=50&lt;BR /&gt;&lt;BR /&gt;But say I replace ${imsi} with a UNIX command such as `date` it work as it supposed to.&lt;BR /&gt;Where did I go wrong ?&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Tue, 08 Feb 2005 04:10:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479749#M847452</guid>
      <dc:creator>Aminur Rizal</dc:creator>
      <dc:date>2005-02-08T04:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479750#M847453</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Try not to use the /bin/csh but the /bin/sh.&lt;BR /&gt;&lt;BR /&gt;csh has to many options, versions and implementations.&lt;BR /&gt;&lt;BR /&gt;use &lt;BR /&gt;&lt;BR /&gt;!#/bin/sh&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Bob</description>
      <pubDate>Tue, 08 Feb 2005 04:17:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479750#M847453</guid>
      <dc:creator>B. Hulst</dc:creator>
      <dc:date>2005-02-08T04:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479751#M847454</link>
      <description>OK Bob,&lt;BR /&gt;I will try that  very soon. Its a long holiday here for the Chinese New Year- so no access to my system yet.&lt;BR /&gt;&lt;BR /&gt;Thanks :)</description>
      <pubDate>Tue, 08 Feb 2005 04:25:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479751#M847454</guid>
      <dc:creator>Aminur Rizal</dc:creator>
      <dc:date>2005-02-08T04:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479752#M847455</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I try always to take the very simple shell /bin/sh or C code or just perl script.&lt;BR /&gt;&lt;BR /&gt;The sh shell is 99% the same in every OS.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Bob</description>
      <pubDate>Tue, 08 Feb 2005 04:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479752#M847455</guid>
      <dc:creator>B. Hulst</dc:creator>
      <dc:date>2005-02-08T04:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479753#M847456</link>
      <description>&lt;BR /&gt;The script you post is riddled with typos.&lt;BR /&gt;To avoid confusion please only cut&amp;amp;paste. Do not re-type.&lt;BR /&gt;&lt;BR /&gt;There is a missing open back-tick before 'sed'&lt;BR /&gt;There is a missing open slash for the sed pattern&lt;BR /&gt;There is a missing closing match ($) on that pattern.&lt;BR /&gt;&lt;BR /&gt;This works for me:&lt;BR /&gt;&lt;BR /&gt;set imsi=`grep IMSI test.out | awk '{print $3}'`&lt;BR /&gt;foreach ki (`sed -n '/var_out/,$p' test.out | sed '1,2d' | awk '{print $7}'`)&lt;BR /&gt;echo ZMAC:IMSI=${imsi}:KI=$ki,UV=50&lt;BR /&gt;end&lt;BR /&gt;&lt;BR /&gt;Now just cut &amp;amp; past that!&lt;BR /&gt;This perl one line also works:&lt;BR /&gt;&lt;BR /&gt;perl -ne '$imsi=(split)[2] if /IMSI/; $data=1 if /var_out/; print "ZMAC:IMSI=${imsi}:KI=".(split)[6].",UV=50\n" if ($data &amp;amp;&amp;amp; ($i++ &amp;gt; 1))' test.out&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But if you wrote it in perl you'd probably want to add more security for example:&lt;BR /&gt;&lt;BR /&gt;$field = "KI";&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  last if ($field_index);&lt;BR /&gt;  $imsi=$1 if (/IMSI\s*:\s*(\S+)/);&lt;BR /&gt;  if (/var_out/) {&lt;BR /&gt;   @words = split("/");&lt;BR /&gt;   while ($x = $words[$i++]) {&lt;BR /&gt;     if ($x eq $field) {&lt;BR /&gt;        $field_index = ++$i;&lt;BR /&gt;        last;&lt;BR /&gt;        }&lt;BR /&gt;     }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;die "No field $field found on line with var_out" unless $field_index;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt; print "ZMAC:IMSI=$imsi:$field=".(split)[$field_index].",UV=50\n";&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will pick up the 'imsi' value with or without spaces around that colon.&lt;BR /&gt;And it will determine the right column for the select field from the var_out line.&lt;BR /&gt;(Admittedly, the way is skips the blank line is a hack :-).&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 08 Feb 2005 08:15:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479753#M847456</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-08T08:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479754#M847457</link>
      <description>Hello , &lt;BR /&gt;&lt;BR /&gt;i found error with "foreach" statement so i used "for" &lt;BR /&gt;&lt;BR /&gt;#!/bin/csh -f&lt;BR /&gt;imsi=`grep IMSI test.out | awk '{print $3}'`&lt;BR /&gt;PI=`sed -n '/var_out/,/^$/p' test.out | awk '{ print $7}'`&lt;BR /&gt;for ki in $PI&lt;BR /&gt;do &lt;BR /&gt;echo "ZMAC:IMSI=${imsi}:KI=${ki},UV=50"&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;and the printout is : &lt;BR /&gt;&lt;BR /&gt;ZMAC:IMSI=5021313872800000096:PI=11111111111111111111111111111111,UV=50&lt;BR /&gt;ZMAC:IMSI=5021313872800000096:PI=11111111111111111111111111111111,UV=50&lt;BR /&gt;ZMAC:IMSI=5021313872800000096:PI=11111111111111111111111111111111,UV=50</description>
      <pubDate>Tue, 08 Feb 2005 10:15:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479754#M847457</guid>
      <dc:creator>Neritan Omari</dc:creator>
      <dc:date>2005-02-08T10:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Echo and foreach loop problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479755#M847458</link>
      <description>Hi All,&lt;BR /&gt;I manage to get it works now. As advised by Hein, I cut and paste the script from here and it works now.&lt;BR /&gt;&lt;BR /&gt;Thanks  a lot.&lt;BR /&gt;You guys are really great!</description>
      <pubDate>Mon, 14 Feb 2005 03:03:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/echo-and-foreach-loop-problem/m-p/3479755#M847458</guid>
      <dc:creator>Aminur Rizal</dc:creator>
      <dc:date>2005-02-14T03:03:26Z</dc:date>
    </item>
  </channel>
</rss>

