<?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: Easy shell scripting question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390714#M199099</link>
    <description>in Korn:&lt;BR /&gt;while read var1 var2&lt;BR /&gt;do&lt;BR /&gt;   # something   &lt;BR /&gt;done &amp;lt; input_file&lt;BR /&gt;&lt;BR /&gt;(If you dont trust input to be nice)&lt;BR /&gt;You can also read as:&lt;BR /&gt;while THE_LINE=$(line)&lt;BR /&gt;do&lt;BR /&gt;    echo $THE_LINE | read var1 var2&lt;BR /&gt;    # something&lt;BR /&gt;done &amp;lt; input_file</description>
    <pubDate>Thu, 30 Sep 2004 09:32:53 GMT</pubDate>
    <dc:creator>Rangarajan Radhakrishna</dc:creator>
    <dc:date>2004-09-30T09:32:53Z</dc:date>
    <item>
      <title>Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390712#M199097</link>
      <description>I have a file that has 15-20 thousand lines like this:&lt;BR /&gt;&lt;BR /&gt;field1 field11&lt;BR /&gt;field222 field22222222&lt;BR /&gt;&lt;BR /&gt;All fields separated by a single space.&lt;BR /&gt;&lt;BR /&gt;I want to run through this script and set a var equal to each of the two fields for a record, then do something else.&lt;BR /&gt;&lt;BR /&gt;EX:&lt;BR /&gt;&lt;BR /&gt;var1=field1&lt;BR /&gt;var2=field11&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Just looking for the most efficient way to do this.&lt;BR /&gt;&lt;BR /&gt;TIA and points for all responses.&lt;BR /&gt;&lt;BR /&gt;Sean&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Sep 2004 09:10:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390712#M199097</guid>
      <dc:creator>Sean OB_1</dc:creator>
      <dc:date>2004-09-30T09:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390713#M199098</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cat file|while read field1 field2 rest&lt;BR /&gt;do&lt;BR /&gt;var1=field1&lt;BR /&gt;var2=field2&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;See &lt;A href="http://www.shelldorado.com" target="_blank"&gt;www.shelldorado.com&lt;/A&gt; for scripting&lt;BR /&gt;&lt;BR /&gt;             Steve Steel</description>
      <pubDate>Thu, 30 Sep 2004 09:24:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390713#M199098</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2004-09-30T09:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390714#M199099</link>
      <description>in Korn:&lt;BR /&gt;while read var1 var2&lt;BR /&gt;do&lt;BR /&gt;   # something   &lt;BR /&gt;done &amp;lt; input_file&lt;BR /&gt;&lt;BR /&gt;(If you dont trust input to be nice)&lt;BR /&gt;You can also read as:&lt;BR /&gt;while THE_LINE=$(line)&lt;BR /&gt;do&lt;BR /&gt;    echo $THE_LINE | read var1 var2&lt;BR /&gt;    # something&lt;BR /&gt;done &amp;lt; input_file</description>
      <pubDate>Thu, 30 Sep 2004 09:32:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390714#M199099</guid>
      <dc:creator>Rangarajan Radhakrishna</dc:creator>
      <dc:date>2004-09-30T09:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390715#M199100</link>
      <description>Sean,&lt;BR /&gt;&lt;BR /&gt;Would something like this work for you?&lt;BR /&gt;&lt;BR /&gt;field1="$(cat &lt;FILENAME&gt; | awk '{print $1}') | echo $field2"&lt;BR /&gt;field11="$(cat &lt;FILENAME&gt; | awk '{print $11}') | echo $field11"&lt;BR /&gt;&lt;BR /&gt;&lt;OR&gt;&lt;BR /&gt;&lt;BR /&gt;for field1 in `$(cat &lt;FILENAME&gt; | awk '{print $1}')`&lt;BR /&gt;    do      &lt;BR /&gt;        for field11 in `$(cat &lt;FILENAME&gt; | awk '{print $11}')` &lt;BR /&gt;            do&lt;BR /&gt;            echo $field1 $field11&lt;BR /&gt;            &lt;WHATEVER else="" you="" want="" to="" do...=""&gt;&lt;BR /&gt;            done&lt;BR /&gt;        done&lt;BR /&gt;&lt;BR /&gt;Just a couple of ideas.  If I had a sample file to test with, I couple probably come up with something a bit more extravagant  :)&lt;BR /&gt;&lt;BR /&gt;Dwyane&lt;/WHATEVER&gt;&lt;/FILENAME&gt;&lt;/FILENAME&gt;&lt;/OR&gt;&lt;/FILENAME&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Thu, 30 Sep 2004 09:35:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390715#M199100</guid>
      <dc:creator>Dwyane Everts_1</dc:creator>
      <dc:date>2004-09-30T09:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390716#M199101</link>
      <description>Ooooppppssss!!!!  A correction&lt;BR /&gt;&lt;BR /&gt;field1="$(cat &lt;FILENAME&gt; | awk '{print $1}')"&lt;BR /&gt;echo $field1&lt;BR /&gt;field11="$(cat &lt;FILENAME&gt; | awk '{print $11}')"&lt;BR /&gt;echo $field11"&lt;BR /&gt;&lt;BR /&gt;got ahead of myself a little bit :)&lt;BR /&gt;&lt;BR /&gt;Dwyane&lt;/FILENAME&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Thu, 30 Sep 2004 09:37:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390716#M199101</guid>
      <dc:creator>Dwyane Everts_1</dc:creator>
      <dc:date>2004-09-30T09:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390717#M199102</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;num=1&lt;BR /&gt;cat &lt;FILE&gt;|while read a b&lt;BR /&gt;do&lt;BR /&gt;echo var$num=$a&lt;BR /&gt;let num="num + 1"&lt;BR /&gt;echo var$num=$b&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...assuming that you want the var_num ascending&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Franky&lt;/FILE&gt;</description>
      <pubDate>Thu, 30 Sep 2004 09:41:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390717#M199102</guid>
      <dc:creator>Franky_1</dc:creator>
      <dc:date>2004-09-30T09:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390718#M199103</link>
      <description>will this work:&lt;BR /&gt;&lt;BR /&gt;cat yourfile | while read line&lt;BR /&gt;do&lt;BR /&gt;read var1 var2 rest&lt;BR /&gt;echo "$var1 $var2"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Thu, 30 Sep 2004 09:43:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390718#M199103</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-09-30T09:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390719#M199104</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;i think a while read should be the most efficient way to do this.&lt;BR /&gt;&lt;BR /&gt;Something like:&lt;BR /&gt;&lt;BR /&gt;while read var1 var2&lt;BR /&gt;do&lt;BR /&gt;# do something here&lt;BR /&gt;done &amp;lt; yourinputfile&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will run through all lines of yourinputfile and for every line you can do something and use var1 for the first field and var2 for the second field. As in your example in the first loop var1 would be "field1" and var2 would be "field11" (without the " of course). In the second loop var1=field222 and var2=field22222222 and so on.&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;Regards Stefan&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Sep 2004 09:47:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390719#M199104</guid>
      <dc:creator>Stefan Schulz</dc:creator>
      <dc:date>2004-09-30T09:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390720#M199105</link>
      <description>Aahhrg 7 answers bevor mine. The Internet connecto to and from Germany seems to show me the answers of the others only when i post one myselfe.&lt;BR /&gt;&lt;BR /&gt;Never mind.&lt;BR /&gt;&lt;BR /&gt;Stefan</description>
      <pubDate>Thu, 30 Sep 2004 09:49:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390720#M199105</guid>
      <dc:creator>Stefan Schulz</dc:creator>
      <dc:date>2004-09-30T09:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390721#M199106</link>
      <description>We can do as,&lt;BR /&gt;&lt;BR /&gt; while read line; do&lt;BR /&gt;&lt;BR /&gt;  var1=$(echo $line | awk '{ print $1 }')&lt;BR /&gt;  var2=$(echo $line | awk '{ print $2 }')&lt;BR /&gt;&lt;BR /&gt;done &amp;lt; &lt;INPUTFILE&gt;&lt;/INPUTFILE&gt;</description>
      <pubDate>Thu, 30 Sep 2004 09:53:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390721#M199106</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-30T09:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390722#M199107</link>
      <description>There is a problem that,&lt;BR /&gt;&lt;BR /&gt;if you store first field and second filed on var1 , var2 only last record's information only available there.&lt;BR /&gt;&lt;BR /&gt;So we can avoid this with array simply as,&lt;BR /&gt;&lt;BR /&gt; # Array index&lt;BR /&gt; index=0&lt;BR /&gt;&lt;BR /&gt; while read line; do&lt;BR /&gt;  &lt;BR /&gt;  var1[$index]=$(echo $line | awk '{ print $1 }')&lt;BR /&gt;  var2[$index]=$(echo $line | awk '{ print $2 }')&lt;BR /&gt;&lt;BR /&gt; let index=index+1&lt;BR /&gt;&lt;BR /&gt; done &amp;lt; &lt;INPUTFILE&gt;&lt;BR /&gt;&lt;BR /&gt; so that &lt;BR /&gt;&lt;BR /&gt;  for first record it is saved as,&lt;BR /&gt; &lt;BR /&gt; echo ${var1[1]} ${var2[1]}&lt;BR /&gt;&lt;BR /&gt;    and nth record as,&lt;BR /&gt; &lt;BR /&gt; echo ${var1[n]} ${var2[n]}&lt;BR /&gt;&lt;BR /&gt;HTH. &lt;BR /&gt;&lt;BR /&gt;&lt;/INPUTFILE&gt;</description>
      <pubDate>Thu, 30 Sep 2004 10:00:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390722#M199107</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-09-30T10:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Easy shell scripting question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390723#M199108</link>
      <description>Hi Sean,&lt;BR /&gt;&lt;BR /&gt;sorry i've missed one line :-(&lt;BR /&gt;&lt;BR /&gt;num=1&lt;BR /&gt;cat &lt;FILE&gt;|while read a b&lt;BR /&gt;do&lt;BR /&gt;echo var$num=$a&lt;BR /&gt;let num="num + 1"&lt;BR /&gt;echo var$num=$b&lt;BR /&gt;let num="num + 1"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Franky&lt;/FILE&gt;</description>
      <pubDate>Thu, 30 Sep 2004 10:05:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/easy-shell-scripting-question/m-p/3390723#M199108</guid>
      <dc:creator>Franky_1</dc:creator>
      <dc:date>2004-09-30T10:05:11Z</dc:date>
    </item>
  </channel>
</rss>

