<?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: scripting - read vars from a file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869549#M98089</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;looks like your more after the part inside the loop?&lt;BR /&gt;How about using the POSIX features of "ps", and suppressing the headline:&lt;BR /&gt;&lt;BR /&gt;UNIX95=. ps -e -C your,processes,go,here -o ruser=,pid=,pcpu=,vsz=,stime=,time=,args= |&lt;BR /&gt;while read ruser pid pcpu vsz stime time args&lt;BR /&gt;do case "$ruser" in&lt;BR /&gt;process#1) do-something-here ;;&lt;BR /&gt;process#2) do-something-else ;;&lt;BR /&gt;esac&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;FWIW,&lt;BR /&gt;Wodisch</description>
    <pubDate>Thu, 26 Dec 2002 23:37:28 GMT</pubDate>
    <dc:creator>Wodisch_1</dc:creator>
    <dc:date>2002-12-26T23:37:28Z</dc:date>
    <item>
      <title>scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869541#M98081</link>
      <description>Trying to read data from a file. First part of the script outputs ps info to a file:&lt;BR /&gt;&lt;BR /&gt;UNIX95= ps -e -o ruser,pid,pcpu,vsz,stime,time,args | grep oracleprod    | grep -v grep | sort -rnk3 &amp;gt;&amp;gt; ./ps.out&lt;BR /&gt;&lt;BR /&gt;Now I want to do a "for i in `cat ./ps.out`" , BUT, every field is on it's own line in the output file. If I cat the file, or even vi the ps.out file, it appears to be fine, as I would expect it to be. &lt;BR /&gt;&lt;BR /&gt;So I either need to find a way to read 7 lines at a time and assign them to different variables, or find a way to fix the formatting of the ps command so it writes the lines correctly.&lt;BR /&gt;&lt;BR /&gt;Any ideas?</description>
      <pubDate>Mon, 23 Dec 2002 17:37:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869541#M98081</guid>
      <dc:creator>Kim Kendall</dc:creator>
      <dc:date>2002-12-23T17:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869542#M98082</link>
      <description>Hi Kim:&lt;BR /&gt;&lt;BR /&gt;To read one line at a time from your file, simply do:&lt;BR /&gt;&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;  your_thing&lt;BR /&gt;done &amp;lt; ps.out&lt;BR /&gt;&lt;BR /&gt;...If you want to read the seven fields comprising each line, do:&lt;BR /&gt;&lt;BR /&gt;while read RUSER PID PCPU VSZ STIME TIME ARGS &lt;BR /&gt;do&lt;BR /&gt;  your_thing&lt;BR /&gt;done &amp;lt; ps.out&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 23 Dec 2002 17:46:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869542#M98082</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-12-23T17:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869543#M98083</link>
      <description>It's 7 fields repeated over and over</description>
      <pubDate>Mon, 23 Dec 2002 17:51:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869543#M98083</guid>
      <dc:creator>Kim Kendall</dc:creator>
      <dc:date>2002-12-23T17:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869544#M98084</link>
      <description>You have several choices (but then it's unix, so you already knew that). Unless you need to retain the results in a file you set UNIX95 seperately from the command (export UNIX95=1, I think will work) and route the output of the ps query to a variable like this:&lt;BR /&gt;&lt;BR /&gt;PS_OUT=`ps -e -o ruser,pid,pcpu,vsz,stime,time,args | grep oracleprod | grep -v grep | sort -rnk3`&lt;BR /&gt;&lt;BR /&gt;(watch the line wrap, all that goes on 1 line)&lt;BR /&gt;&lt;BR /&gt;Next, change the IFS variable to cooperate:&lt;BR /&gt;&lt;BR /&gt;OLD_IFS=$IFS&lt;BR /&gt;IFS="^J"  (that's a control-J, a linefeed only)&lt;BR /&gt;&lt;BR /&gt;Now this construction will give you an entire line at a time:&lt;BR /&gt;&lt;BR /&gt;for LINE in `echo PS_OUT`; do&lt;BR /&gt;   [do your stuff with the data here]&lt;BR /&gt;done&lt;BR /&gt;IFS=$OLD_IFS&lt;BR /&gt;&lt;BR /&gt;The other option you have is leave the ps capture the way you have it and to read from the ps.out file like this:&lt;BR /&gt;&lt;BR /&gt;exec 4&amp;lt;./ps.out&lt;BR /&gt;while read -u4 LINE; do&lt;BR /&gt;   [do your stuff with the data here]&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Depending on the actual format of the file, you may need to alter the IFS variable as above.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;mark</description>
      <pubDate>Mon, 23 Dec 2002 18:12:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869544#M98084</guid>
      <dc:creator>Mark Greene_1</dc:creator>
      <dc:date>2002-12-23T18:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869545#M98085</link>
      <description>A helpful hint with UNIX95 variable.&lt;BR /&gt;&lt;BR /&gt;Don't set it to 1 in /etc/profile or root profile&lt;BR /&gt;&lt;BR /&gt;Havint it set when you sh HP depots can cause crc errors.  Not really, but you won't be able to use the patch.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Mon, 23 Dec 2002 19:11:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869545#M98085</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2002-12-23T19:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869546#M98086</link>
      <description>Hello.&lt;BR /&gt;If you have predefined fields in your file do:&lt;BR /&gt;&lt;BR /&gt;while read -r RUSER PID PCPU VSZ STIME TIME AGRS&lt;BR /&gt;do&lt;BR /&gt;  .... use your $RUSER etc variables here as you want.&lt;BR /&gt;done &amp;lt; ./ps.out&lt;BR /&gt;&lt;BR /&gt;Hope this helps, &lt;BR /&gt;0leg</description>
      <pubDate>Mon, 23 Dec 2002 22:07:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869546#M98086</guid>
      <dc:creator>Oleg Zieaev_1</dc:creator>
      <dc:date>2002-12-23T22:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869547#M98087</link>
      <description>You might use awk, but I suspect if you knew the awk language you would have thought of that already.  awk reads files one line at a time and uses white space as a field seperator.&lt;BR /&gt;&lt;BR /&gt;For example, the output from a 'ps' command might look like this:&lt;BR /&gt;&lt;BR /&gt;gbc 18685 1 0 14:56:03 pts/ta 0:00 /usr/bin/newmail -i90&lt;BR /&gt;&lt;BR /&gt;If you pipe that to awk, within awk each field on the line is assigned a parameter variable:&lt;BR /&gt;&lt;BR /&gt;$0 = the entire line&lt;BR /&gt;$1 = gbc&lt;BR /&gt;$2 = 18685&lt;BR /&gt;$3 = 1&lt;BR /&gt;$4 = 0&lt;BR /&gt;$5 = 14:56:03&lt;BR /&gt;$6 = pts/ta&lt;BR /&gt;$7 = 0:00&lt;BR /&gt;$8 = /usr/bin/newmail&lt;BR /&gt;$9 = -i90&lt;BR /&gt;&lt;BR /&gt;Anyway I can't give you an awk tutorial here but if you already know some shell scripting stuff, you can handle awk.  The best book about the language is "The Awk Programming Language" by Aho, Kernighan and Weinberger.&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Dec 2002 21:10:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869547#M98087</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-12-26T21:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869548#M98088</link>
      <description>...but I also like the "while read line" solution above....&lt;BR /&gt;Fred&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Dec 2002 21:13:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869548#M98088</guid>
      <dc:creator>Fred Martin_1</dc:creator>
      <dc:date>2002-12-26T21:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869549#M98089</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;looks like your more after the part inside the loop?&lt;BR /&gt;How about using the POSIX features of "ps", and suppressing the headline:&lt;BR /&gt;&lt;BR /&gt;UNIX95=. ps -e -C your,processes,go,here -o ruser=,pid=,pcpu=,vsz=,stime=,time=,args= |&lt;BR /&gt;while read ruser pid pcpu vsz stime time args&lt;BR /&gt;do case "$ruser" in&lt;BR /&gt;process#1) do-something-here ;;&lt;BR /&gt;process#2) do-something-else ;;&lt;BR /&gt;esac&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;FWIW,&lt;BR /&gt;Wodisch</description>
      <pubDate>Thu, 26 Dec 2002 23:37:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869549#M98089</guid>
      <dc:creator>Wodisch_1</dc:creator>
      <dc:date>2002-12-26T23:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: scripting - read vars from a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869550#M98090</link>
      <description>Ended up using Mark Greene's idea...&lt;BR /&gt;&lt;BR /&gt;   exec 4&amp;lt;$psout2&lt;BR /&gt;   while read -u4 LINE&lt;BR /&gt;   do&lt;BR /&gt;      _usr=`echo $LINE | awk '{print $1}'`&lt;BR /&gt;      _pid=`echo $LINE | awk '{print $2}'`&lt;BR /&gt;      _cpu=`echo $LINE | awk '{print $3}'`&lt;BR /&gt;      _vsz=`echo $LINE | awk '{print $4}'`&lt;BR /&gt;      _sti=`echo $LINE | awk '{print $5}'`&lt;BR /&gt;      _tim=`echo $LINE | awk '{print $6}'`&lt;BR /&gt;      _arg=`echo $LINE | awk '{print $7}'`&lt;BR /&gt;&lt;BR /&gt;      &lt;ALL the="" stuff="" to="" do=""&gt;&lt;BR /&gt;   done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Not exceptionally elegant, but it works! ;)&lt;BR /&gt;&lt;BR /&gt;&lt;/ALL&gt;</description>
      <pubDate>Fri, 27 Dec 2002 17:15:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/scripting-read-vars-from-a-file/m-p/2869550#M98090</guid>
      <dc:creator>Kim Kendall</dc:creator>
      <dc:date>2002-12-27T17:15:32Z</dc:date>
    </item>
  </channel>
</rss>

