<?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: Awk - help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040640#M95727</link>
    <description>Hi,&lt;BR /&gt;  My test.txt will have lines containing patterns /var, /globa/Tsp...etc.[hard-coded in array] when these are matched, then they should be stored in the variable "position_params".&lt;BR /&gt;&lt;BR /&gt;But your script didn't store the patterns in the variable position_params. It outputs nothing.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Can you help....&lt;BR /&gt;&lt;BR /&gt;Prabu.S</description>
    <pubDate>Wed, 18 Apr 2007 00:23:29 GMT</pubDate>
    <dc:creator>Senthil Prabu.S_1</dc:creator>
    <dc:date>2007-04-18T00:23:29Z</dc:date>
    <item>
      <title>Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040638#M95725</link>
      <description>Hi,&lt;BR /&gt;   I have a script to match a list of patterns defined in array and do some operation. The flow is "array elements are passed into a while loop, where pattern matching on individual elements using awk". It works fine when array element have single "/" like "/var", but awk fails when array element have two slaces like "/global/TspOam". &lt;BR /&gt;&lt;BR /&gt;I knew special characters can be given in "[ ]" to match the pattern, but it didnot help me.&lt;BR /&gt;&lt;BR /&gt;My script looks like this;&lt;BR /&gt;#!/usr/bin/ksh -x&lt;BR /&gt;set -A filesys /var&lt;BR /&gt;&lt;BR /&gt;i=0&lt;BR /&gt;while [ $i -lt ${#filesys[@]} ]&lt;BR /&gt;do&lt;BR /&gt;position_params=`awk ${filesys[$i]}[\^\/]/'{print}' test.txt | grep -v '^[ ]*#'`&lt;BR /&gt;echo $position_params&lt;BR /&gt;((i=i+1))&lt;BR /&gt;done&lt;BR /&gt;........it goes on&lt;BR /&gt;&lt;BR /&gt;When array is populated with elements like "/global/TspOam", awk fails inside the while loop.&lt;BR /&gt;&lt;BR /&gt;Can anyone help me....&lt;BR /&gt;&lt;BR /&gt;Note: &lt;BR /&gt;     Running on solaris 10 OS...&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Prabu.S</description>
      <pubDate>Tue, 17 Apr 2007 08:16:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040638#M95725</guid>
      <dc:creator>Senthil Prabu.S_1</dc:creator>
      <dc:date>2007-04-17T08:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040639#M95726</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;on Solaris boxes I generally do not recommend to use plain 'awk' - it's normally an ancient version:&lt;BR /&gt;ls -goi /usr/bin/*awk&lt;BR /&gt;     26691 -r-xr-xr-x   2   89128 Jan  8 19:30 /usr/bin/awk&lt;BR /&gt;     26694 -r-xr-xr-x   1  126964 Jan  8 19:30 /usr/bin/nawk&lt;BR /&gt;     26691 -r-xr-xr-x   2   89128 Jan  8 19:30 /usr/bin/oawk&lt;BR /&gt;&lt;BR /&gt;Just try first&lt;BR /&gt;nawk (= /usr/bin/nawk)&lt;BR /&gt;then&lt;BR /&gt;/usr/xpg4/bin/awk&lt;BR /&gt;&lt;BR /&gt;Next - which is NOT Solaris specific stuff:&lt;BR /&gt;- there's no need for grep - awk can do it by itself much more efficient. I guess you want to drop lines commented out by this.&lt;BR /&gt;- your awk-command is really doubtful, because match operator and your pattern itself get mixed up. Having no 'test.txt' I can only guess what result you want to get, however.&lt;BR /&gt;&lt;BR /&gt;Try this (&lt;BR /&gt;I use the match operator and set a variable 'pat' to clarify the pattern):&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh -x&lt;BR /&gt;set -A filesys /var /usr/bin&lt;BR /&gt;&lt;BR /&gt;typeset -i i=0&lt;BR /&gt;while [ $i -lt ${#filesys[@]} ]&lt;BR /&gt;do&lt;BR /&gt;position_params=$(nawk -v fsys=${filesys[$i]} 'BEGIN {pat="^"fsys"[^/]*"}&lt;BR /&gt;/^[ ]*#/ {next}&lt;BR /&gt;$0 ~ pat {print}' test.txt)&lt;BR /&gt;echo $position_params&lt;BR /&gt;((i=i+1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Apr 2007 09:15:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040639#M95726</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-04-17T09:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040640#M95727</link>
      <description>Hi,&lt;BR /&gt;  My test.txt will have lines containing patterns /var, /globa/Tsp...etc.[hard-coded in array] when these are matched, then they should be stored in the variable "position_params".&lt;BR /&gt;&lt;BR /&gt;But your script didn't store the patterns in the variable position_params. It outputs nothing.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Can you help....&lt;BR /&gt;&lt;BR /&gt;Prabu.S</description>
      <pubDate>Wed, 18 Apr 2007 00:23:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040640#M95727</guid>
      <dc:creator>Senthil Prabu.S_1</dc:creator>
      <dc:date>2007-04-18T00:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040641#M95728</link>
      <description>Hi Prabu,&lt;BR /&gt;why awk and not simply grep?&lt;BR /&gt;This runs fine on my HP-UX11i:&lt;BR /&gt;set -A filesys /var /globa/Tsp&lt;BR /&gt;typeset -i i=0&lt;BR /&gt;while [ $i -lt ${#filesys[@]} ]&lt;BR /&gt;do&lt;BR /&gt;position_params=$(grep ${filesys[$i]} test.txt)&lt;BR /&gt;echo $i $position_params&lt;BR /&gt;((i=i+1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;0 /var&lt;BR /&gt;1 /globa/Tsp&lt;BR /&gt;&lt;BR /&gt;cat test.txt&lt;BR /&gt;/var&lt;BR /&gt;/globa/Tsp&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Wed, 18 Apr 2007 03:05:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040641#M95728</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2007-04-18T03:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040642#M95729</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;what do you mean:&lt;BR /&gt;&amp;gt;&amp;gt;&lt;BR /&gt;hardcoded in array&lt;BR /&gt;&amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;The following code - slightly modified to my prior solution - produces this output:&lt;BR /&gt;/usr/bin udir&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;set -A filesys /var /usr/bin&lt;BR /&gt;typeset -i i=0&lt;BR /&gt;cat &amp;gt;test.txt &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;/var/tmp tmpdir&lt;BR /&gt;/usr/local hostdir&lt;BR /&gt;#/var sysdir&lt;BR /&gt;/usr udir&lt;BR /&gt;/usr/bin udir&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;while [ $i -lt ${#filesys[@]} ]&lt;BR /&gt;do&lt;BR /&gt;position_params=$(nawk -v fsys=${filesys[$i]} 'BEGIN {pat="^"fsys"$"}&lt;BR /&gt;/^[ ]*#/ {next}&lt;BR /&gt;$1 ~ pat {print}' test.txt)&lt;BR /&gt;[ -n "$position_params" ] &amp;amp;&amp;amp; echo $position_params&lt;BR /&gt;((i=i+1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Now let us know, what are your exact input and output request.&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Apr 2007 04:23:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040642#M95729</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-04-18T04:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040643#M95730</link>
      <description>Hello Peter,&lt;BR /&gt;   I modified your first script to get it working..:-)Thanks a lot!!!!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And closing this thread.</description>
      <pubDate>Wed, 18 Apr 2007 05:49:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040643#M95730</guid>
      <dc:creator>Senthil Prabu.S_1</dc:creator>
      <dc:date>2007-04-18T05:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Awk - help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040644#M95731</link>
      <description>Got the solution, closing it.</description>
      <pubDate>Wed, 18 Apr 2007 05:50:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-help/m-p/5040644#M95731</guid>
      <dc:creator>Senthil Prabu.S_1</dc:creator>
      <dc:date>2007-04-18T05:50:38Z</dc:date>
    </item>
  </channel>
</rss>

