<?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: shell script question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809820#M83997</link>
    <description>Since you say that you are that familiar with awk, I'' use a simple example that parses your input lines and then reads them into distinct shell variables. I use 4 variables in this example:&lt;BR /&gt;&lt;BR /&gt;INFILE=/tmp/myfile&lt;BR /&gt;&lt;BR /&gt;awk -F':' '{print $1, $2, $3, $4}' &amp;lt; ${INFILE} | while read A B C D&lt;BR /&gt;do&lt;BR /&gt;  echo "A=${A}"&lt;BR /&gt;  echo "B=${B}"&lt;BR /&gt;  echo "C=${C}"&lt;BR /&gt;  echo "D=${D}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;If less than four fields are found on a given input record (a line) then only those found will have non-null values.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 19 Sep 2002 15:09:24 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2002-09-19T15:09:24Z</dc:date>
    <item>
      <title>shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809817#M83994</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am parsing lines in a file delimited by colons. &lt;BR /&gt;&lt;BR /&gt;Can someone give me a clever line in awk or POSIX that will assign $VAR1=field1 $VAR2=field2, etc?&lt;BR /&gt;&lt;BR /&gt;I need to loop through each line and do work on $VAR1 and $VAR2.&lt;BR /&gt;&lt;BR /&gt;I can only pass files to the cut command, not each line that I parse with my "for" statement.&lt;BR /&gt;&lt;BR /&gt;I'm not that familiar with awk.&lt;BR /&gt;&lt;BR /&gt;Thanks!</description>
      <pubDate>Thu, 19 Sep 2002 14:58:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809817#M83994</guid>
      <dc:creator>Allan Pincus</dc:creator>
      <dc:date>2002-09-19T14:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809818#M83995</link>
      <description>awk -F: '{var1 = $1; var2 = $2}'&lt;BR /&gt;man on awk will show that you can define the field delimiter with the -F option, and inside of awk you can set anything equel to anything.  &lt;BR /&gt;If you want to get external variables, look at the awk man pages for the -v option, which is variable assignment prior to running awk.&lt;BR /&gt;&lt;BR /&gt;Not really sure what you mean though by setting $VAR2=field2 and what your trying to accomplish though... perhaps telling us what these are will help get more accurate answers.&lt;BR /&gt;I.E.  awk has $0, $1, etc... where is the $var and field coming from?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Shannon</description>
      <pubDate>Thu, 19 Sep 2002 15:04:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809818#M83995</guid>
      <dc:creator>Shannon Petry</dc:creator>
      <dc:date>2002-09-19T15:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809819#M83996</link>
      <description>example /etc/passwd &lt;BR /&gt;&lt;BR /&gt; awk -F':' '{ print $1}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Thu, 19 Sep 2002 15:09:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809819#M83996</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2002-09-19T15:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809820#M83997</link>
      <description>Since you say that you are that familiar with awk, I'' use a simple example that parses your input lines and then reads them into distinct shell variables. I use 4 variables in this example:&lt;BR /&gt;&lt;BR /&gt;INFILE=/tmp/myfile&lt;BR /&gt;&lt;BR /&gt;awk -F':' '{print $1, $2, $3, $4}' &amp;lt; ${INFILE} | while read A B C D&lt;BR /&gt;do&lt;BR /&gt;  echo "A=${A}"&lt;BR /&gt;  echo "B=${B}"&lt;BR /&gt;  echo "C=${C}"&lt;BR /&gt;  echo "D=${D}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;If less than four fields are found on a given input record (a line) then only those found will have non-null values.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Sep 2002 15:09:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809820#M83997</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-09-19T15:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809821#M83998</link>
      <description>What about this .. (processing the /etc/passwd file for example) ..&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;IFS=:&lt;BR /&gt;exec 0while read -r Name PW Uid Gid Gecos Home Shell&lt;BR /&gt;do&lt;BR /&gt;  VAR1=$Name&lt;BR /&gt;  VAR2=$Pass&lt;BR /&gt;  VAR3=$Uid&lt;BR /&gt;  ....&lt;BR /&gt;  &lt;DO your="" thing="" ..=""&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;/DO&gt;</description>
      <pubDate>Thu, 19 Sep 2002 15:09:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809821#M83998</guid>
      <dc:creator>S.K. Chan</dc:creator>
      <dc:date>2002-09-19T15:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809822#M83999</link>
      <description>Hi Allan:&lt;BR /&gt;&lt;BR /&gt;Something like:&lt;BR /&gt;&lt;BR /&gt;# V=b&lt;BR /&gt;# echo "a:one\nb:two\nc:three"|awk -F: -v V=$V '$1~V {print $2}'&lt;BR /&gt;&lt;BR /&gt;...would echo "two" from the record "b".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Sep 2002 15:11:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809822#M83999</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-09-19T15:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809823#M84000</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You can do this directly is the shell as follows:-&lt;BR /&gt;&lt;BR /&gt;If reading directly from a file...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;IFS=:&lt;BR /&gt;{&lt;BR /&gt;while read var1 var2 rest&lt;BR /&gt;do&lt;BR /&gt; &lt;PROCESS variables=""&gt;...&lt;BR /&gt;done&lt;BR /&gt;} &amp;lt; &lt;FILENAME&gt;&lt;BR /&gt;unset IFS&lt;BR /&gt;&lt;BR /&gt;If reading from a pipe...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;IFS=:&lt;BR /&gt;&lt;PIPELINE&gt; | {&lt;BR /&gt;while read var1 var2 rest&lt;BR /&gt;do&lt;BR /&gt; &lt;PROCESS variables=""&gt;...&lt;BR /&gt;done&lt;BR /&gt;}&lt;BR /&gt;unset IFS&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John&lt;/PROCESS&gt;&lt;/PIPELINE&gt;&lt;/FILENAME&gt;&lt;/PROCESS&gt;</description>
      <pubDate>Thu, 19 Sep 2002 15:12:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809823#M84000</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2002-09-19T15:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809824#M84001</link>
      <description>awk -F: '{print $1, $2}' filename | while read var1 var2&lt;BR /&gt;do&lt;BR /&gt;echo $var1 $var2&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Darrell</description>
      <pubDate>Thu, 19 Sep 2002 15:13:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809824#M84001</guid>
      <dc:creator>Darrell Allen</dc:creator>
      <dc:date>2002-09-19T15:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809825#M84002</link>
      <description>If you are not that familiar with awk, you might try perl. Using /etc/passwd as the data file,&lt;BR /&gt;&lt;BR /&gt;perl -F: -nae 'print $F[0], "\n"' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;The "-F" sets the separator character.&lt;BR /&gt;Each line gets split into the F array, numbered 0..n, so instead of printing the variable out, you can modify it within the perl script.&lt;BR /&gt;&lt;BR /&gt;Tom</description>
      <pubDate>Thu, 19 Sep 2002 15:20:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809825#M84002</guid>
      <dc:creator>Tom Maloy</dc:creator>
      <dc:date>2002-09-19T15:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809826#M84003</link>
      <description>Darrell,&lt;BR /&gt;&lt;BR /&gt;Your answer was the easiest!!  Exactly what I needed.&lt;BR /&gt;&lt;BR /&gt;I could have done this in Perl, but its clumsy when you have a bunch of shell commands, so I didn't use it.&lt;BR /&gt;&lt;BR /&gt;Thanks everyone!!!&lt;BR /&gt;&lt;BR /&gt;- Allan</description>
      <pubDate>Thu, 19 Sep 2002 16:11:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809826#M84003</guid>
      <dc:creator>Allan Pincus</dc:creator>
      <dc:date>2002-09-19T16:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: shell script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809827#M84004</link>
      <description>You can use cut or awk if you like. I used this example file (I named it /tmp/test):&lt;BR /&gt;&lt;BR /&gt;oravp1:8940:221:/usr/bin/csh&lt;BR /&gt;vq1adm:9277:224:/usr/bin/csh&lt;BR /&gt;oravq1:9276:221:/usr/bin/csh&lt;BR /&gt;rbillard:6498:10000:/usr/bin/sh&lt;BR /&gt;sanman:11574:20:/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;and this script:&lt;BR /&gt;&lt;BR /&gt;for lines in $(do&lt;BR /&gt;VAR1=`echo $lines|cut -f 1 -d:`&lt;BR /&gt;VAR2=`echo $lines|cut -f 2 -d:`&lt;BR /&gt;VAR3=`echo $lines|cut -f 3 -d:`&lt;BR /&gt;VAR4=`echo $lines|cut -f 4 -d:`&lt;BR /&gt;echo "VAR1=$VAR1"&lt;BR /&gt;echo "VAR2=$VAR2"&lt;BR /&gt;echo "VAR3=$VAR3"&lt;BR /&gt;echo "VAR4=$VAR4"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and got this output:&lt;BR /&gt;&lt;BR /&gt;VAR1=oravp1&lt;BR /&gt;VAR2=8940&lt;BR /&gt;VAR3=221&lt;BR /&gt;VAR4=/usr/bin/csh&lt;BR /&gt;VAR1=vq1adm&lt;BR /&gt;VAR2=9277&lt;BR /&gt;VAR3=224&lt;BR /&gt;VAR4=/usr/bin/csh&lt;BR /&gt;VAR1=oravq1&lt;BR /&gt;VAR2=9276&lt;BR /&gt;VAR3=221&lt;BR /&gt;VAR4=/usr/bin/csh&lt;BR /&gt;VAR1=rbillard&lt;BR /&gt;VAR2=6498&lt;BR /&gt;VAR3=10000&lt;BR /&gt;VAR4=/usr/bin/sh&lt;BR /&gt;VAR1=sanman&lt;BR /&gt;VAR2=11574&lt;BR /&gt;VAR3=20&lt;BR /&gt;VAR4=/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;You could replace the cut -fx -d: with awk -F: '{print $x}'. Either will work.&lt;BR /&gt;&lt;BR /&gt;Keit</description>
      <pubDate>Fri, 20 Sep 2002 03:21:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-question/m-p/2809827#M84004</guid>
      <dc:creator>Keith Clark</dc:creator>
      <dc:date>2002-09-20T03:21:18Z</dc:date>
    </item>
  </channel>
</rss>

