<?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: how to pass shell variable value into awk scripts in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009404#M96283</link>
    <description>&lt;!--!*#--&gt;&amp;gt;Through above my.awk scripts I want to check field "s5" (new position of this field is from 55 to 59). I want to replace this field with 0.1 if this field value is 0.0.&lt;BR /&gt;&lt;BR /&gt;If you are talking about the s5 variable above that you have extracted from 47 to 53, you can just use:&lt;BR /&gt;if (s5 == 0.0) s5 = 0.1&lt;BR /&gt;&lt;BR /&gt;If you print this numeric value, you may have to use printf to have a fixed field width.  Otherwise you can treat s5 as a character string.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;If possible can you also let me know in sed.&lt;BR /&gt;&lt;BR /&gt;If you have "  0.0" in columns 55..59, you could use this sed script:&lt;BR /&gt;$ sed -e 's/^\(\{54\}\)  0\.0\/\1  0.1/' file&lt;BR /&gt;&lt;BR /&gt;(There are two spaces before the "0" for a field width of 5.)</description>
    <pubDate>Thu, 31 May 2007 06:01:18 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2007-05-31T06:01:18Z</dc:date>
    <item>
      <title>how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009396#M96275</link>
      <description>Hi Guys,&lt;BR /&gt;&lt;BR /&gt;I want to pass x.sh variable value(userid) into my.awk scripts in "s4" value.&lt;BR /&gt;I excute following my.awk file from x.sh. And "s4" field passed the "userid" value into&lt;BR /&gt;TMPTRANSACT.TXT file.&lt;BR /&gt;&lt;BR /&gt;----------------------&lt;BR /&gt;       x.sh&lt;BR /&gt;----------------------&lt;BR /&gt;userid="428"                    &lt;BR /&gt;cd /appl/outgoing/incoming                    &lt;BR /&gt;awk -f my.awk TRANSACT.DAT &amp;gt; "TMPTRANSACT.TXT"&lt;BR /&gt;&lt;BR /&gt;----------------------&lt;BR /&gt;      my.awk&lt;BR /&gt;----------------------&lt;BR /&gt;{                                       &lt;BR /&gt;s1=substr($0,1,30)&lt;BR /&gt;s2="  1"&lt;BR /&gt;s3=substr($0,31,16)&lt;BR /&gt;s4=---&amp;gt;Here i want to get x.sh variale "userid" value.&lt;BR /&gt;s5=substr($0,47,7)&lt;BR /&gt;s6="E"&lt;BR /&gt;s7=substr($0,54,5)&lt;BR /&gt;s8=substr($0,59,5)&lt;BR /&gt;s9=substr($0,64,5)                      &lt;BR /&gt;s10="E"                                 &lt;BR /&gt;s11="     0.000E  0.00 000 000000000"   &lt;BR /&gt;print s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11&lt;BR /&gt;}                                       &lt;BR /&gt;----------------------------------------&lt;BR /&gt;&lt;BR /&gt;Can you guide me how to get shell scripts value into awk scripts.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Manish</description>
      <pubDate>Tue, 29 May 2007 16:28:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009396#M96275</guid>
      <dc:creator>MANISH PATEL_2</dc:creator>
      <dc:date>2007-05-29T16:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009397#M96276</link>
      <description>In x.sh do...&lt;BR /&gt;&lt;BR /&gt;awk -v uid=$userid -f my.awk TRANSACT.DAT &amp;gt; "TMPTRANSACT.TXT"&lt;BR /&gt;</description>
      <pubDate>Tue, 29 May 2007 16:31:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009397#M96276</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-29T16:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009398#M96277</link>
      <description>Use the -v awk option. Multiple -v options are allowed to allow you to pass n options to awk.&lt;BR /&gt;&lt;BR /&gt;awk -v "myvar1=${MYVAR1}" -v "mickey=Mickey Mouse" -v myvar2=${USERNAME}" -f my.awk &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;&lt;BR /&gt;It's getnerally a good idea to enclose the entire -v "myvar=${X}" string in double quotes to preserve whitespace. In this example, the awk variable is "myvar" and it gets assigned whatever the current value of the shell variable $X happens to be.</description>
      <pubDate>Tue, 29 May 2007 16:44:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009398#M96277</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2007-05-29T16:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009399#M96278</link>
      <description>Hi Manish:&lt;BR /&gt;&lt;BR /&gt;Modern versions of 'awk' support the '-v' option for passing variables.  Older versions insist the the external assignment is made as part of the argument list passed. Compare:&lt;BR /&gt;&lt;BR /&gt;# awk -v VAR="world" 'BEGIN{print "hello",VAR}' /dev/null &lt;BR /&gt;&lt;BR /&gt;# awk -v VAR="world" 'END{print "hello",VAR}' /dev/null&lt;BR /&gt;&lt;BR /&gt;# awk 'BEGIN{print "hello",VAR}' VAR="world" /dev/null&lt;BR /&gt;&lt;BR /&gt;# awk 'END{print "hello",VAR}' VAR="world" /dev/null&lt;BR /&gt;&lt;BR /&gt;Note particularly the diffence in output in the third form. The advanage to the '-v arg=value' form is that variable assignment occurs even before the 'BEGIN' rules are executed.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 29 May 2007 16:55:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009399#M96278</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-29T16:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009400#M96279</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;I would also note that it is appropriate and courteous to consider this guideline:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://forums1.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;https://forums1.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 29 May 2007 16:59:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009400#M96279</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-29T16:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009401#M96280</link>
      <description>Hi Sandman&lt;BR /&gt;&lt;BR /&gt;Thanks for your help. Infect all other scripts also work file.&lt;BR /&gt;&lt;BR /&gt;Can you pls help me how can i check the o value and replace with 1 through awk.&lt;BR /&gt;&lt;BR /&gt;Through above my.awk scripts i want to check field "s5" (new position of this field is from 55 to 59). I want to replace this field with 0.1 if this field value is 0.0.&lt;BR /&gt;Can you please let me know how can i write script. If possible can you also let me know in sed.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Manish</description>
      <pubDate>Wed, 30 May 2007 16:03:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009401#M96280</guid>
      <dc:creator>MANISH PATEL_2</dc:creator>
      <dc:date>2007-05-30T16:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009402#M96281</link>
      <description>Hey&lt;BR /&gt;&lt;BR /&gt;Check the sub function:&lt;BR /&gt;&lt;BR /&gt;sub(regexp, replacement [, target])&lt;BR /&gt;&lt;BR /&gt;example&lt;BR /&gt;str = "water, water, everywhere"&lt;BR /&gt;sub(/at/, "ith", str)&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 30 May 2007 16:14:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009402#M96281</guid>
      <dc:creator>Oviwan</dc:creator>
      <dc:date>2007-05-30T16:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009403#M96282</link>
      <description>&amp;gt;Through above my.awk scripts i want to check field "s5" (new position of this &amp;gt;field is from 55 to 59). I want to replace this field with 0.1 if this field value is &amp;gt;0.0. Can you please let me know how can i write script. If possible can you &amp;gt;also let me know in sed.&lt;BR /&gt;&lt;BR /&gt;I am not sure I understand your requirement? Could you please provide an example of what you are looking to get done?&lt;BR /&gt;&lt;BR /&gt;~thanks</description>
      <pubDate>Wed, 30 May 2007 16:48:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009403#M96282</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-05-30T16:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009404#M96283</link>
      <description>&lt;!--!*#--&gt;&amp;gt;Through above my.awk scripts I want to check field "s5" (new position of this field is from 55 to 59). I want to replace this field with 0.1 if this field value is 0.0.&lt;BR /&gt;&lt;BR /&gt;If you are talking about the s5 variable above that you have extracted from 47 to 53, you can just use:&lt;BR /&gt;if (s5 == 0.0) s5 = 0.1&lt;BR /&gt;&lt;BR /&gt;If you print this numeric value, you may have to use printf to have a fixed field width.  Otherwise you can treat s5 as a character string.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;If possible can you also let me know in sed.&lt;BR /&gt;&lt;BR /&gt;If you have "  0.0" in columns 55..59, you could use this sed script:&lt;BR /&gt;$ sed -e 's/^\(\{54\}\)  0\.0\/\1  0.1/' file&lt;BR /&gt;&lt;BR /&gt;(There are two spaces before the "0" for a field width of 5.)</description>
      <pubDate>Thu, 31 May 2007 06:01:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009404#M96283</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-05-31T06:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to pass shell variable value into awk scripts</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009405#M96284</link>
      <description>Hi Manish:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Through above my.awk scripts i want to check field "s5" (new position of this &amp;gt;field is from 55 to 59). I want to replace this field with 0.1 if this field value is 0.0. Can you please let me know how can i write script.&lt;BR /&gt;&lt;BR /&gt;Perl's 'substr' can be used as an lvalue or can take a fourth argument as a replacement string.  Hence you could do, by example:&lt;BR /&gt;&lt;BR /&gt;# echo "abc0.0def"|perl -pe 'substr($_,3,3,"0.1") if substr($_,3,3)=="0.0"'&lt;BR /&gt;&lt;BR /&gt;Perl counts 0-relative.  Hence, here, every line that contains "0.0" in positions 3-5 is replaced by "0.1".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 31 May 2007 08:50:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-shell-variable-value-into-awk-scripts/m-p/4009405#M96284</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-05-31T08:50:04Z</dc:date>
    </item>
  </channel>
</rss>

