<?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: Query on scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553011#M678833</link>
    <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;One advantage to Jean-Philippe's use of a unique file descriptor would be seen if your read loop invoked an interactive command, like 'rm -i' to remove files.  In that case, you need to keep one file descriptor for the file read (here, #3) and allow the standard file descriptor (STDIN or #0) to be used by 'rm -i ${i}'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Tue, 22 Dec 2009 13:10:18 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-12-22T13:10:18Z</dc:date>
    <item>
      <title>Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553001#M678823</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;(A) If I have a file called data that contains the following:&lt;BR /&gt;&lt;BR /&gt;abc&lt;BR /&gt;def&lt;BR /&gt;ghi&lt;BR /&gt;&lt;BR /&gt;I can use script to perform task like:&lt;BR /&gt;&lt;BR /&gt;for i in `cat $data`&lt;BR /&gt;do&lt;BR /&gt;echo $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;(B) What if the file contains the following:&lt;BR /&gt;&lt;BR /&gt;abc     123&lt;BR /&gt;def     456&lt;BR /&gt;ghi     789&lt;BR /&gt;&lt;BR /&gt;How to reference the first column data and second column data if I would like to perform the same thing as (A) in shell script?&lt;BR /&gt;</description>
      <pubDate>Sun, 20 Dec 2009 08:12:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553001#M678823</guid>
      <dc:creator>yc_2</dc:creator>
      <dc:date>2009-12-20T08:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553002#M678824</link>
      <description>&lt;!--!*#--&gt;Much better to remove the evil cat in (A):&lt;BR /&gt;for i in $(&amp;lt; $data); do&lt;BR /&gt;&lt;BR /&gt;&amp;gt;How to reference the first column data and second column data if I would like to perform the same thing as (A) in shell script?&lt;BR /&gt;&lt;BR /&gt;You can use while read:&lt;BR /&gt;while read first second dummy; do&lt;BR /&gt;   echo "$first $second"&lt;BR /&gt;done &amp;lt; data&lt;BR /&gt;&lt;BR /&gt;"dummy" eats up any third, etc columns.</description>
      <pubDate>Sun, 20 Dec 2009 08:20:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553002#M678824</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-20T08:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553003#M678825</link>
      <description>Thanks</description>
      <pubDate>Sun, 20 Dec 2009 08:28:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553003#M678825</guid>
      <dc:creator>yc_2</dc:creator>
      <dc:date>2009-12-20T08:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553004#M678826</link>
      <description>Hey;&lt;BR /&gt;&lt;BR /&gt;In addition, you can also do something like:&lt;BR /&gt;&lt;BR /&gt;cat ${file | while read line&lt;BR /&gt;do&lt;BR /&gt;   echo "${line}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Note the quotes around the variable.  That syntax comes in handy if your datafile has lines with one parameter, others with two or more...&lt;BR /&gt;&lt;BR /&gt;Once you have the "line" in ${line}, you can then parse it out however you want.&lt;BR /&gt;&lt;BR /&gt;HTH;&lt;BR /&gt;&lt;BR /&gt;Doug&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Dec 2009 00:50:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553004#M678826</guid>
      <dc:creator>Doug O'Leary</dc:creator>
      <dc:date>2009-12-21T00:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553005#M678827</link>
      <description>Where should the "}" put in cat ${file | while read line</description>
      <pubDate>Mon, 21 Dec 2009 02:29:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553005#M678827</guid>
      <dc:creator>yc_2</dc:creator>
      <dc:date>2009-12-21T02:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553006#M678828</link>
      <description>&lt;!--!*#--&gt;&amp;gt; cat ${file | while read line&lt;BR /&gt;&lt;BR /&gt;&amp;gt;  Where should the "}" put in&lt;BR /&gt;&amp;gt; cat ${file | while read line&lt;BR /&gt;&lt;BR /&gt;cat ${file}&lt;BR /&gt;&lt;BR /&gt;Again, "cat" is not really needed.  For&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;bash$ cat sh1.sh&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;(&lt;BR /&gt;while read line ; do&lt;BR /&gt;     echo "${line}"&lt;BR /&gt;done&lt;BR /&gt;) &amp;lt; $1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;bash$ ./sh1.sh sh1.sh&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;(&lt;BR /&gt;while read line ; do&lt;BR /&gt;echo "${line}"&lt;BR /&gt;done&lt;BR /&gt;) &amp;lt; $1</description>
      <pubDate>Mon, 21 Dec 2009 03:16:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553006#M678828</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-12-21T03:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553007#M678829</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Where should the "}" put in cat ${file | while read line&lt;BR /&gt;&lt;BR /&gt;Doug's post had a typographical error in that the closing brace was lost.  The syntax he meant to use was:&lt;BR /&gt;&lt;BR /&gt;cat ${file} | while read line&lt;BR /&gt;&lt;BR /&gt;Enclosing shell variables in curly braces to signal parameter substitution is a good practice to develop.  The 'sh-poxix' manpages noted that, "Braces are required when parameter is followed by a letter, digit, or underscore that should not be interpreted as part of its name or when a named parameter is subscripted."&lt;BR /&gt;&lt;BR /&gt;As Dennis first noted, using a 'cat' process to read a file whose input is then piped to a shell 'read' is wasting a process.  The shell can do the read without another process and is thus more efficient.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Dec 2009 13:05:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553007#M678829</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-21T13:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553008#M678830</link>
      <description>&lt;!--!*#--&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;If I may write my own version which is slightly different than Dennis' :&lt;BR /&gt;&lt;BR /&gt;exec 3&amp;lt; $data&lt;BR /&gt;while read -u3 fist second dummy ; do&lt;BR /&gt;      print "$first $second"&lt;BR /&gt;done&lt;BR /&gt;exec 3&amp;lt;&amp;amp;-&lt;BR /&gt;&lt;BR /&gt;The advantages are that :&lt;BR /&gt;&lt;BR /&gt;  1) it shows which file you're processing since the beginning of the loop;&lt;BR /&gt;  &lt;BR /&gt;  2) you might open several files at the same time by changing the file descriptor (exec 3&amp;lt; $data 4&amp;lt; $data2 5&amp;lt; $data3).&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Jean-Philippe</description>
      <pubDate>Mon, 21 Dec 2009 16:10:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553008#M678830</guid>
      <dc:creator>Jean-Philippe Henry</dc:creator>
      <dc:date>2009-12-21T16:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553009#M678831</link>
      <description>&amp;gt; exec 3&amp;lt; $data&lt;BR /&gt;&lt;BR /&gt;What does 3 means?</description>
      <pubDate>Tue, 22 Dec 2009 01:21:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553009#M678831</guid>
      <dc:creator>yc_2</dc:creator>
      <dc:date>2009-12-22T01:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553010#M678832</link>
      <description>&amp;gt;What does 3 means?&lt;BR /&gt;&lt;BR /&gt;File number 3.  The next free one after stdin(0), stdout(1) and stderr(2).&lt;BR /&gt;(Perhaps it is better to leave well enough alone and skip the more fancy exec stuff.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Jean-Philippe: 1) it shows which file you're processing since the beginning of the loop&lt;BR /&gt;&lt;BR /&gt;If that's important, a comment is more descriptive than fancy exec and read -u.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;2) you might open several files at the same time ... (exec 3&amp;lt; $data 4&amp;lt; $data2 5&amp;lt; $data3).&lt;BR /&gt;&lt;BR /&gt;It might be more understandable with one per line.</description>
      <pubDate>Tue, 22 Dec 2009 01:43:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553010#M678832</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-22T01:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553011#M678833</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;One advantage to Jean-Philippe's use of a unique file descriptor would be seen if your read loop invoked an interactive command, like 'rm -i' to remove files.  In that case, you need to keep one file descriptor for the file read (here, #3) and allow the standard file descriptor (STDIN or #0) to be used by 'rm -i ${i}'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 22 Dec 2009 13:10:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553011#M678833</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-22T13:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Query on scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553012#M678834</link>
      <description>&amp;gt;JRF: One advantage to Jean-Philippe's use of a unique file descriptor would be seen if your read loop invoked an interactive command, like 'rm -i' to remove files. In that case, you need to keep one file descriptor for the file read and allow the standard file descriptor (STDIN) to be used by 'rm -i ${i}'.&lt;BR /&gt;&lt;BR /&gt;It is possible that rm(1) isn't reading from stdin, most likely stderr?  tusc will tell you.&lt;BR /&gt;&lt;BR /&gt;I thought of that solution the last time we had that "while ssh/remsh ... with -n" eating up stdin.</description>
      <pubDate>Tue, 22 Dec 2009 14:23:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/query-on-scripting/m-p/4553012#M678834</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-22T14:23:39Z</dc:date>
    </item>
  </channel>
</rss>

