<?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: accessing ksh variables in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951022#M290258</link>
    <description>I apologize, but I haven't carefully read your request.&lt;BR /&gt;But if it's only passing shell variables to awk this is quite simply done by appending a list of parameters to your awk invocation like this:&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;SH_VAR1=Hello&lt;BR /&gt;SH_VAR2=World&lt;BR /&gt;&lt;BR /&gt;awk '{some valid awk here}' /some/file/to/parse_over var1=$SH_VAR1 var2=$SH_VAR2&lt;BR /&gt;&lt;BR /&gt;In your awk code you can refer to var1, var2, ...&lt;BR /&gt;&lt;BR /&gt;More modern awk versions (like gawk, or HP's awk) also offer the -v option to pass shell variables (see manpage)&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Ralph</description>
    <pubDate>Mon, 26 Feb 2007 04:34:28 GMT</pubDate>
    <dc:creator>Ralph Grothe</dc:creator>
    <dc:date>2007-02-26T04:34:28Z</dc:date>
    <item>
      <title>accessing ksh variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951020#M290256</link>
      <description>hi everybody!&lt;BR /&gt;i am running this ksh script for replacing a set of strings by another set of new ones. i am getting both these from a file.&lt;BR /&gt;also, the strings that i want to replace, are sub-strings(can occur more than once in each chunk) in a big chunk of data that i have bulk-copied(bcp utility) from a database. i can do it successfully, but it so happens that some of the set of strings that need to be replaced are mutually sub-strings of eachother. like for example, the file containing the sets of strings includes the following::&lt;BR /&gt;&lt;BR /&gt;abc abc:x&lt;BR /&gt;abcd abcl.x&lt;BR /&gt;...etc.&lt;BR /&gt;&lt;BR /&gt;now while replacement with the first set of strings the instances of the second string get altered...&lt;BR /&gt;abc:xd&lt;BR /&gt;&lt;BR /&gt;i am trying to use gawk FIELDWIDTHS for this with the following code snippet:&lt;BR /&gt;&lt;BR /&gt;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;cp ${ORIGFILE} ${TMPFILE}&lt;BR /&gt;&lt;BR /&gt;sed "s/\*/\\\*/g" ${SYMLISTFILE} &amp;gt; ${NEWSYMLIST}&lt;BR /&gt;while read OLDSYM NEWSYM FLDLEN&lt;BR /&gt;do&lt;BR /&gt;        gawk 'BEGIN{ FIELDWIDTHS = ${FLDLEN} } END{ s/${OLDSYM}/${NEWSYM}/g }'&lt;BR /&gt;#      sed "s/${OLDSYM}/${NEWSYM}/g" ${TMPFILE} &amp;gt; ${INFILE}&lt;BR /&gt;        cp ${INFILE} ${TMPFILE}&lt;BR /&gt;done &amp;lt; ${NEWSYMLIST}&lt;BR /&gt;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;while running the script now i get the following error for the ${FLDLEN}::&lt;BR /&gt;gawk: cmd. line:1: BEGIN{ FIELDWIDTHS = ${FLDLEN} } END{ s/${OLDSYM}/${NEWSYM}/g }&lt;BR /&gt;gawk: cmd. line:1:                      ^ parse error&lt;BR /&gt;&lt;BR /&gt;please can anyone help me writing a viable code that can access the FLDLEN from the ksh script to the gawk script?&lt;BR /&gt;is gawk freely available to install... and is its installation the solution?&lt;BR /&gt;&lt;BR /&gt;Thanking you in advance,&lt;BR /&gt;Tru.&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Feb 2007 02:22:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951020#M290256</guid>
      <dc:creator>Trupti Wagh</dc:creator>
      <dc:date>2007-02-26T02:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: accessing ksh variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951021#M290257</link>
      <description>I apologize, but I haven't carefully read your request.&lt;BR /&gt;But if it's only passing shell variables to awk this is quite simply done by appending a list of parameters to your awk invocation like this:&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;SH_VAR1=Hello&lt;BR /&gt;SH_VAR2=World&lt;BR /&gt;&lt;BR /&gt;awk '{some valid awk here}' /some/file/to/parse_over var1=SH_VAR1 var2=SH_VAR2&lt;BR /&gt;&lt;BR /&gt;In your awk code you can refer to var1, var2, ...&lt;BR /&gt;&lt;BR /&gt;More modern awk versions (like gawk, or HP's awk) also offer the -v option to pass shell variables (see manpage)&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Ralph</description>
      <pubDate>Mon, 26 Feb 2007 04:34:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951021#M290257</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-02-26T04:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: accessing ksh variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951022#M290258</link>
      <description>I apologize, but I haven't carefully read your request.&lt;BR /&gt;But if it's only passing shell variables to awk this is quite simply done by appending a list of parameters to your awk invocation like this:&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;SH_VAR1=Hello&lt;BR /&gt;SH_VAR2=World&lt;BR /&gt;&lt;BR /&gt;awk '{some valid awk here}' /some/file/to/parse_over var1=$SH_VAR1 var2=$SH_VAR2&lt;BR /&gt;&lt;BR /&gt;In your awk code you can refer to var1, var2, ...&lt;BR /&gt;&lt;BR /&gt;More modern awk versions (like gawk, or HP's awk) also offer the -v option to pass shell variables (see manpage)&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Ralph</description>
      <pubDate>Mon, 26 Feb 2007 04:34:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951022#M290258</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-02-26T04:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: accessing ksh variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951023#M290259</link>
      <description>Sorry, for that twin posting again.&lt;BR /&gt;The itrc webserver wasn't as responsive.</description>
      <pubDate>Mon, 26 Feb 2007 04:38:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951023#M290259</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2007-02-26T04:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: accessing ksh variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951024#M290260</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;first: you'll have to sort your substition pattern in reverse order, so no multiple operations are done for one pattern.&lt;BR /&gt;&lt;BR /&gt;Second: your gawk sysntax is broken:&lt;BR /&gt;- ${var} is NOT a valid awk syntax&lt;BR /&gt;- single quoting of for commands will prevent shell variables to be expanded.&lt;BR /&gt;&lt;BR /&gt;My solution creates an sed-script for your changes. Since there may be only 99 lines in a sed script, thre may be the need to split one langer sed commandfile into pieces ('man split').&lt;BR /&gt;&lt;BR /&gt;I assume, the format of NEWSYMLIST is&lt;BR /&gt;before&lt;SPACE&gt;after&lt;BR /&gt;and there is NO SPACE in both pattern 'before' and 'after'. Note that a 's' command of sed will take the first char following as the delimiter, which will be a SPACE in our case here.&lt;BR /&gt;&lt;BR /&gt;sort -r -k1 $NEWSYMLIST |&lt;BR /&gt;sed -e 's/^/ /' -e 's/$/ d/' &amp;gt;/tmp/sed.cmd&lt;BR /&gt;&lt;BR /&gt;if [ $(wc -l &lt;/SPACE&gt;then&lt;BR /&gt;  # Only move if it was successfull&lt;BR /&gt;  if sed -f /tmp/sed.cmd $ORIGFILE &amp;gt;$TMFILE&lt;BR /&gt;  then&lt;BR /&gt;    cp $ORIGFILE $ORIGFILE.orig&lt;BR /&gt;    cp $TMFILE $ORIGFILE&lt;BR /&gt;  fi&lt;BR /&gt;else # you have to split&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Mon, 26 Feb 2007 07:16:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/accessing-ksh-variables/m-p/3951024#M290260</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-02-26T07:16:31Z</dc:date>
    </item>
  </channel>
</rss>

