<?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: Another awk question - pattern matching an internal var in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867640#M821576</link>
    <description>Hi Tony:&lt;BR /&gt;&lt;BR /&gt;Now that I've had coffee, let's shorten what you appear to want.  It appears that upon a match to a STRING anchored to the beginning of the line you merely desire to append 'uname' to the line's end.  If you *really* mean the evaluated 'uname' then enclose it in backticks like this:&lt;BR /&gt;&lt;BR /&gt;awk -v OPTION=^STRING -v NAME=`uname` '{if ($0~OPTION) {print $0 NAME} print $0}' filename|more&lt;BR /&gt;&lt;BR /&gt;Again, note the -v OPTION=^STRING and the NAME=`uname`.  You don't need to 'sub' -- just 'print $0 NAME'.&lt;BR /&gt;&lt;BR /&gt;Since 'uname' returns "HP-UX" you might want 'hostname' instead.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
    <pubDate>Thu, 19 Dec 2002 13:00:20 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2002-12-19T13:00:20Z</dc:date>
    <item>
      <title>Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867637#M821573</link>
      <description>Hello again!&lt;BR /&gt;&lt;BR /&gt;Yesterday I was helped out with some syntax and got the following awk statement which works FINE - adding a string to the end of a pattern matched line.&lt;BR /&gt;&lt;BR /&gt;awk '{if (/^STRING:/) { sub($0,$0"uname:")} print $0 }' filename | more&lt;BR /&gt;&lt;BR /&gt;Now, as I intend to perform this on a number of STRINGS and unames I intend to do something like this:&lt;BR /&gt;&lt;BR /&gt;awk -v OPTION=STRING -v NAME=uname '{if (/^OPTION:/) { sub($0,$0"NAME:")} print $0 }' filename | more&lt;BR /&gt;&lt;BR /&gt;Basically I need a hand with the syntax as it is simply trying to pattern match the literal string OPTION and not my variable. I've tried escape characters and $ signs but to no avail.. I'm sure there is a nice simple solution to this so I await your replies. Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Tony&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Dec 2002 12:22:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867637#M821573</guid>
      <dc:creator>Tony Walker</dc:creator>
      <dc:date>2002-12-19T12:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867638#M821574</link>
      <description>Hi Tony:&lt;BR /&gt;&lt;BR /&gt;# awk -v OPTION=^STRING -v NAME=TAKE '{if ($0~OPTION) {sub($0,$0"NAME")}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Dec 2002 12:34:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867638#M821574</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-12-19T12:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867639#M821575</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;Oops, I dropped the last part and forgot too unquote your "NAME":&lt;BR /&gt;&lt;BR /&gt;# awk -v OPTION=^xxx -v NAME=TAKE '{if ($0~OPTION) {sub($0,$0 NAME)} print $0}' filename|more&lt;BR /&gt;&lt;BR /&gt;Notice, too, that the anchor (^) is part of the variable value as passed.  The 'NAME' is *not* quoted, too.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Dec 2002 12:40:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867639#M821575</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-12-19T12:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867640#M821576</link>
      <description>Hi Tony:&lt;BR /&gt;&lt;BR /&gt;Now that I've had coffee, let's shorten what you appear to want.  It appears that upon a match to a STRING anchored to the beginning of the line you merely desire to append 'uname' to the line's end.  If you *really* mean the evaluated 'uname' then enclose it in backticks like this:&lt;BR /&gt;&lt;BR /&gt;awk -v OPTION=^STRING -v NAME=`uname` '{if ($0~OPTION) {print $0 NAME} print $0}' filename|more&lt;BR /&gt;&lt;BR /&gt;Again, note the -v OPTION=^STRING and the NAME=`uname`.  You don't need to 'sub' -- just 'print $0 NAME'.&lt;BR /&gt;&lt;BR /&gt;Since 'uname' returns "HP-UX" you might want 'hostname' instead.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Dec 2002 13:00:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867640#M821576</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-12-19T13:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867641#M821577</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;OPTION=STRING&lt;BR /&gt;awk  -v NAME=uname  '/^'$OPTION'/ {printf("%s:"NAME"\n",$0)}' file&lt;BR /&gt;&lt;BR /&gt;Chris&lt;BR /&gt;&lt;BR /&gt;Points ?? ;-)</description>
      <pubDate>Thu, 19 Dec 2002 13:20:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867641#M821577</guid>
      <dc:creator>Christian Gebhardt</dc:creator>
      <dc:date>2002-12-19T13:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867642#M821578</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;Thanks for the replies and confirming why you always get so many points;)&lt;BR /&gt;&lt;BR /&gt;Good point with the lack of need for the sub command (I'm always looking to shorten my commands. Alas I wrote uname as a short-term for username - but the thought is appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;BR /&gt;&lt;BR /&gt;Tony</description>
      <pubDate>Thu, 19 Dec 2002 13:55:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867642#M821578</guid>
      <dc:creator>Tony Walker</dc:creator>
      <dc:date>2002-12-19T13:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867643#M821579</link>
      <description>James, just tried this and found that it prints the line twice. Once with my amendment and once the unchanged $0...</description>
      <pubDate>Thu, 19 Dec 2002 14:20:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867643#M821579</guid>
      <dc:creator>Tony Walker</dc:creator>
      <dc:date>2002-12-19T14:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867644#M821580</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Or perhaps do it with sed ?&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;OPTION=STRING&lt;BR /&gt;NAME=UNAME&lt;BR /&gt;FILE=i.data&lt;BR /&gt;sed 's;^'$OPTION':.*$;&amp;amp;'$NAME';' $FILE&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Thu, 19 Dec 2002 15:08:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867644#M821580</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-12-19T15:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Another awk question - pattern matching an internal var</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867645#M821581</link>
      <description>Hi Tony:&lt;BR /&gt;&lt;BR /&gt;Oops, this is really not my day!&lt;BR /&gt;&lt;BR /&gt;# awk -v OPTION=^STRING -v NAME="&amp;lt;&amp;lt;&amp;lt;" '{if ($0~OPTION) {print $0 NAME} else {print $0}}' filename&lt;BR /&gt;&lt;BR /&gt;...or...&lt;BR /&gt;&lt;BR /&gt;# awk -v OPTION=^STRING -v NAME="&amp;lt;&amp;lt;&amp;lt;" '$0~OPTION {$0=$0 NAME};{print $0}' filename&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Dec 2002 15:12:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-awk-question-pattern-matching-an-internal-var/m-p/2867645#M821581</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-12-19T15:12:51Z</dc:date>
    </item>
  </channel>
</rss>

