<?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: Pipe output to shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133994#M153579</link>
    <description>Hi Bo --&lt;BR /&gt;&lt;BR /&gt;Someone mentioned the "while read" method which you seemed to like.  That's a nice quick'n'dirty technique, but for large input files (&amp;gt;1000 lines?), it can have severe performance problems.&lt;BR /&gt;&lt;BR /&gt;Once you get the script loop working, you might want to convert the "while read" guts into awk, then simply put into your ksh script:  &lt;BR /&gt;&lt;BR /&gt;cat - | awk 'your program'&lt;BR /&gt;&lt;BR /&gt;then pipe into your script just like you did with the "while read" version of the script:&lt;BR /&gt;&lt;BR /&gt;cat your-data | your-script.ksh&lt;BR /&gt;&lt;BR /&gt;In a real-life example, processing data that took 30 minutes with "while read" took only 90 seconds with "awk" (I don't remember how big the file was).  It has something to do with the shell buffering only 1 char at a time versus awk buffering 1K chars at a time.&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;&lt;BR /&gt;=:-)    Alex&lt;BR /&gt;</description>
    <pubDate>Thu, 04 Dec 2003 08:01:02 GMT</pubDate>
    <dc:creator>Alex Ostapenko</dc:creator>
    <dc:date>2003-12-04T08:01:02Z</dc:date>
    <item>
      <title>Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133988#M153573</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;I want to pipe the output from a command to a shell script to process it.&lt;BR /&gt;e.g. cat file1.txt|shellscript.sh &lt;BR /&gt;How can i process the data from within the shellscript.sh ?&lt;BR /&gt;I tried $1 but that's only for parameters.&lt;BR /&gt;Any suggestions?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;Bo</description>
      <pubDate>Tue, 02 Dec 2003 15:25:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133988#M153573</guid>
      <dc:creator>Johan Barelds</dc:creator>
      <dc:date>2003-12-02T15:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133989#M153574</link>
      <description>You would be better off passing the file name to the script as an argument and then using cat, awk, sed, etc. within your script to process the data feil the file.&lt;BR /&gt;&lt;BR /&gt;# ./shellscript.sh /tmp/file1.txt&lt;BR /&gt;&lt;BR /&gt;# cat shellscript.sh&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;FILE=$1&lt;BR /&gt;&lt;BR /&gt;awk 'some awk stuff' $FILE&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Dec 2003 15:28:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133989#M153574</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2003-12-02T15:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133990#M153575</link>
      <description>I would add this kind of processing loop to the shellscript.&lt;BR /&gt;&lt;BR /&gt;while read -r aa&lt;BR /&gt;do&lt;BR /&gt;   var=$aa&lt;BR /&gt;   # do some processing&lt;BR /&gt;done &amp;lt; $1&lt;BR /&gt;&lt;BR /&gt;You can input the filename to be processed as $1&lt;BR /&gt;&lt;BR /&gt;shellscript.sh file1.txt&lt;BR /&gt;&lt;BR /&gt;SEP&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Dec 2003 15:29:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133990#M153575</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2003-12-02T15:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133991#M153576</link>
      <description>You need to use the "read" or "line" commands.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;while read A B C&lt;BR /&gt;do&lt;BR /&gt;  echo "A=${A} B=${B} C=${C}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;That will read stdin until EOF. If there are more than three variables to parse anything beynd the 2 argument will be combined in ${C}.&lt;BR /&gt;&lt;BR /&gt;man sh-posix for details.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Dec 2003 15:29:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133991#M153576</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-12-02T15:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133992#M153577</link>
      <description>Thanks all!&lt;BR /&gt;&lt;BR /&gt;The "while read xx" loop was what i was looking for!&lt;BR /&gt;&lt;BR /&gt;Grz. Bo</description>
      <pubDate>Tue, 02 Dec 2003 15:33:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133992#M153577</guid>
      <dc:creator>Johan Barelds</dc:creator>
      <dc:date>2003-12-02T15:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133993#M153578</link>
      <description>&lt;BR /&gt;to use a file as a input it depends on what you are trying to accomplish.. &lt;BR /&gt;&lt;BR /&gt;I define variables from information in the file, then use the variable within the script.. &lt;BR /&gt;&lt;BR /&gt;If you need to read information from the file in a and perform a task based on multiple variables using a for-loop or do-while is very useful... &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;For example: &lt;BR /&gt;&lt;BR /&gt;export PEIDBNAME&lt;BR /&gt;echo $PEIDBNAME&lt;BR /&gt;export DIST&lt;BR /&gt;echo $DIST&lt;BR /&gt;awk '{print $1,$2,$3,$4,$5,$6,$7,$8}' $DIST$BUILD|pr -c 2 -t&lt;BR /&gt;echo "Enter Build # supported by this printer:\c"&lt;BR /&gt;read bldgnum&lt;BR /&gt;echo $bldgnum&lt;BR /&gt;touch /tmp/btemp&lt;BR /&gt;chmod 666 /tmp/btemp&lt;BR /&gt;export BN=`grep "$bldgnum" $DIST$BUILD`&lt;BR /&gt;echo $BN&lt;BR /&gt;grep "$BN" $DIST$BUILD &amp;gt;/tmp/btemp&lt;BR /&gt;export BNAME=`awk '{print tolower(substr($2,1,3))}' /tmp/btemp`&lt;BR /&gt;echo $BNAME&lt;BR /&gt;export BNAME2=`awk '{print substr($2,1,3)}' /tmp/btemp`&lt;BR /&gt;echo $BNAME2&lt;BR /&gt;#clear&lt;BR /&gt;&lt;BR /&gt;#### SEE $DIST$BUILD EXAMPLE BELOW: &lt;BR /&gt;# more conbuild&lt;BR /&gt;        001 ADMINISTRATION BUILDING&lt;BR /&gt;        002 HIGH SCHOOL&lt;BR /&gt;        003 MIDDLE SCHOOL&lt;BR /&gt;        004 ELEMENTARY SCHOOL&lt;BR /&gt;        005 SPECIAL ED SCHOOL &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ANOTHER EXAMPLE &lt;BR /&gt;##### &lt;BR /&gt;search for a string in a file and create another file... &lt;BR /&gt;&lt;BR /&gt;####&lt;BR /&gt;&lt;BR /&gt;echo "Enter the School District ID to exclude from the passwd file:"&lt;BR /&gt;read $dist&lt;BR /&gt;grep -v -h $dist passwd.org &amp;gt; passwd.restricted&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#####&lt;BR /&gt;ANOTHER EXAMPLE &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;which your shell script for input information you can use a for loop or do while .. &lt;BR /&gt;&lt;BR /&gt;### CREATING A TEMP FILE ####&lt;BR /&gt;&lt;BR /&gt;echo "Enter the District to Alert:\c"&lt;BR /&gt;read dst&lt;BR /&gt;echo "Please Enter the message you want to send:\c"&lt;BR /&gt;read mssg&lt;BR /&gt;echo "Please Enter your Name:\c"&lt;BR /&gt;read name&lt;BR /&gt;&lt;BR /&gt;usrmsg |grep "$dst"|awk '{print $2, $3}'&amp;gt; /tmp/usralert&lt;BR /&gt;for fgls in `awk '{print $1}' /tmp/usralert`&lt;BR /&gt;do&lt;BR /&gt;export FGLSERVER=$fgls&lt;BR /&gt;export LOGNAME=`grep "$fgls" /tmp/usralert |awk '{print $2}'`&lt;BR /&gt;echo $FGLSERVER $LOGNAME $dst $mssg $name&lt;BR /&gt;fglrun message.42r "$mssg" "$name"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Just a couple of thoughts and ways I handle it.. &lt;BR /&gt;&lt;BR /&gt;the beauty of Un*x is there are a hundred ways to do one operation.. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Dec 2003 09:52:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133993#M153578</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2003-12-03T09:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133994#M153579</link>
      <description>Hi Bo --&lt;BR /&gt;&lt;BR /&gt;Someone mentioned the "while read" method which you seemed to like.  That's a nice quick'n'dirty technique, but for large input files (&amp;gt;1000 lines?), it can have severe performance problems.&lt;BR /&gt;&lt;BR /&gt;Once you get the script loop working, you might want to convert the "while read" guts into awk, then simply put into your ksh script:  &lt;BR /&gt;&lt;BR /&gt;cat - | awk 'your program'&lt;BR /&gt;&lt;BR /&gt;then pipe into your script just like you did with the "while read" version of the script:&lt;BR /&gt;&lt;BR /&gt;cat your-data | your-script.ksh&lt;BR /&gt;&lt;BR /&gt;In a real-life example, processing data that took 30 minutes with "while read" took only 90 seconds with "awk" (I don't remember how big the file was).  It has something to do with the shell buffering only 1 char at a time versus awk buffering 1K chars at a time.&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;&lt;BR /&gt;=:-)    Alex&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Dec 2003 08:01:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133994#M153579</guid>
      <dc:creator>Alex Ostapenko</dc:creator>
      <dc:date>2003-12-04T08:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pipe output to shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133995#M153580</link>
      <description>The difference with awk and the shell is that the shell cannot buffer, because processes inside the while loop could also need the same stdin... awk is one process and can buffer because no other commands inside the 'loop' will need the stdin without using the awk itself.&lt;BR /&gt;&lt;BR /&gt;The speed advantage also depends on what you want to do inside the loop. If you only do some pattern matching and re-formatting, awk is the way to go. But if you need to run difficult unix commands from it, the shell could be a better solution.</description>
      <pubDate>Thu, 04 Dec 2003 08:15:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pipe-output-to-shell-script/m-p/3133995#M153580</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2003-12-04T08:15:29Z</dc:date>
    </item>
  </channel>
</rss>

