<?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 operand !~ not working? in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108779#M91435</link>
    <description>Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I did add a colon but didnt use -F for the delimiter.&lt;BR /&gt;&lt;BR /&gt;Well, if you are going to manually edit '/etc/passwd', you should use 'vipw' [on HP-UX, but if this is AIX there isn't one].&lt;BR /&gt;&lt;BR /&gt;Too, its a good thing to run 'pwck' (or maybe 'pwdck' on AIX) if you have kludged '/etc/passwd'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Wed, 14 May 2008 11:48:36 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2008-05-14T11:48:36Z</dc:date>
    <item>
      <title>awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108768#M91424</link>
      <description>Hello all,&lt;BR /&gt;&lt;BR /&gt;I cant get the !~ operand to work - my syntax:&lt;BR /&gt;&lt;BR /&gt;awk '/GIO-ES-UAM\:/ {if ($0 !~ /^\+@GIO/) print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;so I am looking for the string GIO-ES-UAM in /etc/passwd and if not then print etc ...&lt;BR /&gt;&lt;BR /&gt;I get no output however if I add +@GIO-ES-UAM: into /etc/passwd and run:&lt;BR /&gt;&lt;BR /&gt;awk '/GIO-ES-UAM\:/ {if ($0 ~ /^\+@GIO/) print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;this works?&lt;BR /&gt;&lt;BR /&gt;can someone see where my mistake lies?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Wed, 14 May 2008 08:47:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108768#M91424</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-14T08:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108769#M91425</link>
      <description>Hi Chris,&lt;BR /&gt;&lt;BR /&gt;If I get your question correctly:&lt;BR /&gt;&lt;BR /&gt;awk -F: '$0 ~ /\+@GIO-ES-UAM/ {print "+@GIO-ES-UAM:"}' passwd&lt;BR /&gt;&lt;BR /&gt;Otherwise, please explain in detail.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Rasheed Tamton.</description>
      <pubDate>Wed, 14 May 2008 09:40:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108769#M91425</guid>
      <dc:creator>Rasheed Tamton</dc:creator>
      <dc:date>2008-05-14T09:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108770#M91426</link>
      <description>ok my question is&lt;BR /&gt;&lt;BR /&gt;I want to search for the string "+@GIO-ES-UAM:" in /etc/passwd - if the string does not exist in /etc/passwd I want awk to print the string.&lt;BR /&gt;&lt;BR /&gt;I have used !~ (logical not) in the if statement but it wont print.&lt;BR /&gt;&lt;BR /&gt;can you see where i am going wrong with my syntax?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 14 May 2008 09:52:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108770#M91426</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-14T09:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108771#M91427</link>
      <description>awk -F: '$0 !~ /\+@GIO-ES-UAM/ {print "+@GIO-ES-UAM:"}' passwd&lt;BR /&gt;&lt;BR /&gt;But this will print the string for all the lines it gets as input from the passwd file.&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt;Regards.</description>
      <pubDate>Wed, 14 May 2008 10:36:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108771#M91427</guid>
      <dc:creator>Rasheed Tamton</dc:creator>
      <dc:date>2008-05-14T10:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108772#M91428</link>
      <description>I run your example&lt;BR /&gt;&lt;BR /&gt;awk '$0 ~ /\+@GIO-ES-UAM/ {print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;and there is no output to the command .....&lt;BR /&gt;&lt;BR /&gt;I run awk '$0 !~ /\+@GIO-ES-UAM/ {print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;and I get a print "+@GIO-ES-UAM:" for each line in etc passwd.&lt;BR /&gt;&lt;BR /&gt;root@tstestcl.eu.unilever.com # awk '$0 !~ /\+@GIO-ES-UAM/ {print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;+@GIO-ES-UAM:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I want this to be displayed if there is no entry for "+@GIO-ES-UAM:" in /etc/passwd.&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 10:37:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108772#M91428</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-14T10:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108773#M91429</link>
      <description>&lt;!--!*#--&gt;&amp;gt;I can't get the !~ operand to work - my syntax:&lt;BR /&gt;&lt;BR /&gt;awk '/GIO-ES-UAM\:/ {if ($0 !~ /^\+@GIO/) print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;This seems to search for "GIO-ES-UAM:".  (Why are you quoting a ":"?)&lt;BR /&gt;Then it prints lines that don't start with "+@GIO"&lt;BR /&gt;&lt;BR /&gt;&amp;gt;so I am looking for the string GIO-ES-UAM in /etc/passwd and if not then print etc ...&lt;BR /&gt;&lt;BR /&gt;Why not pipe two greps to do the two searches?&lt;BR /&gt;$ grep "GIO-ES-UAM:" /etc/passwd | grep -v "+@GIO"&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I get no output however if I add +@GIO-ES-UAM: into /etc/passwd and run:&lt;BR /&gt;awk '/GIO-ES-UAM\:/ {if ($0 ~ /^\+@GIO/) print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;This prints if you match both.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I want to search for the string "+@GIO-ES-UAM:" in /etc/passwd - if the string does not exist in /etc/passwd I want awk to print the string.&lt;BR /&gt;&lt;BR /&gt;You want to search the WHOLE file and if doesn't exist print a string?  Why not just use grep?&lt;BR /&gt;fgrep -q "GIO-ES-UAM:" /etc/passwd&lt;BR /&gt;if [ $? -ne 0 ]; then&lt;BR /&gt;   echo "+@GIO-ES-UAM:"&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;&amp;gt;can you see where i am going wrong with my syntax?&lt;BR /&gt;&lt;BR /&gt;We either need some more details or an example file.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I want this to be displayed if there is no entry for "+@GIO-ES-UAM:" in /etc/passwd.&lt;BR /&gt;&lt;BR /&gt;If you want this in awk, you must use flag programming.  You set the flag if you find it and print it at the end:&lt;BR /&gt;awk '&lt;BR /&gt;BEGIN { found = 0 }&lt;BR /&gt;/GIO-ES-UAM:/ { found = 1 }&lt;BR /&gt;END { if (!found) print "+@GIO-ES-UAM:" }' /etc/passwd</description>
      <pubDate>Wed, 14 May 2008 10:41:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108773#M91429</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-14T10:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108774#M91430</link>
      <description>You could optimize this and stop when you find it:&lt;BR /&gt;awk '&lt;BR /&gt;/GIO-ES-UAM:/ { exit }&lt;BR /&gt;END { print "+@GIO-ES-UAM:" }' /etc/passwd</description>
      <pubDate>Wed, 14 May 2008 10:48:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108774#M91430</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-14T10:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108775#M91431</link>
      <description>ok i can see where your going with this ....&lt;BR /&gt;&lt;BR /&gt;it doesnt work because my logic is out of sync?&lt;BR /&gt;&lt;BR /&gt;I am searching for any occurance of GIO-ES-UAM in /etc/passwd with '/GIO-ES-UAM/.&lt;BR /&gt;&lt;BR /&gt;if it doesnt exist I run if ($0 !~ /\^+@GIO-ES-UAM:/) print etc etc ....&lt;BR /&gt;&lt;BR /&gt;as this is not logical ....&lt;BR /&gt;&lt;BR /&gt;I'll use grep - and thanks&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 10:57:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108775#M91431</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-14T10:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108776#M91432</link>
      <description>&amp;gt;it doesn't work because my logic is out of sync?&lt;BR /&gt;&lt;BR /&gt;Basically awk (and sed) work on each line of the input file.  You want something that works on all lines and then returns a status or message.  You can do that with END {}.</description>
      <pubDate>Wed, 14 May 2008 11:06:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108776#M91432</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-05-14T11:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108777#M91433</link>
      <description>Hi Chris:&lt;BR /&gt;&lt;BR /&gt;You are saying that you want to match the character sequence "GIO-ES-UAM:" *anywhere* in a record, *and* then using the matched record, if the *beginning* character sequence is *not* "+@GIO", then print.&lt;BR /&gt;&lt;BR /&gt;So you are looking for NIS entries.  I suspect that you are interested in one whose GECOS field (#5) contains "GIO-ES-UAM".  If that's the case, you could specify '-F:' as the 'awk' field delimiter and match on $5 and $1:&lt;BR /&gt;&lt;BR /&gt;# awk -F: '{if ($1~/\+@GIO/ &amp;amp;&amp;amp; $5~/GIO-ES-UAM/) print "+@GIO-ES-UAM:"}' /etc/passwd&lt;BR /&gt;&lt;BR /&gt;You said:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I get no output however if I add +@GIO-ES-UAM: into /etc/passwd and run [my command[.&lt;BR /&gt;&lt;BR /&gt;You didn't add the extra colon (which would be an extra field delimiter) did you?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 11:18:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108777#M91433</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-14T11:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108778#M91434</link>
      <description>I did add a colon but didnt use -F for the delimiter.&lt;BR /&gt;&lt;BR /&gt;:-</description>
      <pubDate>Wed, 14 May 2008 11:44:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108778#M91434</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-14T11:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108779#M91435</link>
      <description>Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I did add a colon but didnt use -F for the delimiter.&lt;BR /&gt;&lt;BR /&gt;Well, if you are going to manually edit '/etc/passwd', you should use 'vipw' [on HP-UX, but if this is AIX there isn't one].&lt;BR /&gt;&lt;BR /&gt;Too, its a good thing to run 'pwck' (or maybe 'pwdck' on AIX) if you have kludged '/etc/passwd'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 14 May 2008 11:48:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108779#M91435</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-05-14T11:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: awk operand !~ not working?</title>
      <link>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108780#M91436</link>
      <description>James ...&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; You are saying that you want to match the character sequence "GIO-ES-UAM:" *anywhere* in a record, *and* then using the matched record, if the *beginning* character sequence is *not* "+@GIO", then print. &amp;lt;&amp;lt;&lt;BR /&gt;&lt;BR /&gt;yes this is correct james but have worked out that by doing the it prints every line that is not matched - I think I have chosen the wrong tool for my problem so will use shell ksh syntax.&lt;BR /&gt;&lt;BR /&gt;:-)&lt;BR /&gt;&lt;BR /&gt;Thanks all.&lt;BR /&gt;</description>
      <pubDate>Wed, 14 May 2008 11:50:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/awk-operand-not-working/m-p/5108780#M91436</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-05-14T11:50:22Z</dc:date>
    </item>
  </channel>
</rss>

