<?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 script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850803#M93532</link>
    <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Take look at this link, it will help you.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce0857bd90a9d611abdb0090277a778c,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce0857bd90a9d611abdb0090277a778c,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;&lt;BR /&gt;Robert-Jan.</description>
    <pubDate>Sun, 24 Nov 2002 11:15:02 GMT</pubDate>
    <dc:creator>Robert-Jan Goossens</dc:creator>
    <dc:date>2002-11-24T11:15:02Z</dc:date>
    <item>
      <title>AWK script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850801#M93530</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I have an AWK script written below to change the 2nd entry in a text file. The text file has the following structure:&lt;BR /&gt;&lt;BR /&gt;#cat myFile.txt&lt;BR /&gt;bill:g68hjdh78gh:100:88&lt;BR /&gt;harry:bft647hsds:7876:77&lt;BR /&gt;... (the list continues)&lt;BR /&gt;&lt;BR /&gt;The script is written as follows:&lt;BR /&gt;#cat awk_test.sh&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;awk &amp;lt;  myFile.txt&lt;BR /&gt;'BEGIN{&lt;BR /&gt;   FS = ":"&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;   split($0, field, ":")  #split fields delimited by :&lt;BR /&gt;    if(field[1] ~ /^bill$/)&lt;BR /&gt;    {&lt;BR /&gt;       field[2]=`head -1 pattern`    &lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;END{&lt;BR /&gt;   print field[1]&lt;BR /&gt;   print field[2]&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;I executed the script as:&lt;BR /&gt;# awk_test.sh&lt;BR /&gt;However, the 2nd field was not at all modified with the new value specified from the file "pattern". &lt;BR /&gt;#cat pattern&lt;BR /&gt;dhsgh777&lt;BR /&gt;&lt;BR /&gt;Also I get an error message for the line&lt;BR /&gt;field[2]=`head -1 pattern`, which says:&lt;BR /&gt;&lt;BR /&gt;awk_test.sh: = dhsgh777: command not found      &lt;BR /&gt;&lt;BR /&gt;Could someone show me how I could modify the script to solve this error and at the same time modify the 2nd field in the file "myFile.txt" ? &lt;BR /&gt;&lt;BR /&gt;I'm a newbie in AWK scripting.&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Sun, 24 Nov 2002 10:31:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850801#M93530</guid>
      <dc:creator>Chern Jian Leaw</dc:creator>
      <dc:date>2002-11-24T10:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: AWK script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850802#M93531</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;The second field in the passwd file is encrypted !!!!! it is not possible to change this by replacing this field with awk or sed or wathever filter. Think you have better luck using the command &lt;BR /&gt;&lt;BR /&gt;#passwd user&lt;BR /&gt;&lt;BR /&gt;Robert-Jan.</description>
      <pubDate>Sun, 24 Nov 2002 10:48:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850802#M93531</guid>
      <dc:creator>Robert-Jan Goossens</dc:creator>
      <dc:date>2002-11-24T10:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: AWK script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850803#M93532</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Take look at this link, it will help you.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce0857bd90a9d611abdb0090277a778c,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xce0857bd90a9d611abdb0090277a778c,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;&lt;BR /&gt;Robert-Jan.</description>
      <pubDate>Sun, 24 Nov 2002 11:15:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850803#M93532</guid>
      <dc:creator>Robert-Jan Goossens</dc:creator>
      <dc:date>2002-11-24T11:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: AWK script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850804#M93533</link>
      <description>the line field[2]=`head -1 pattern` is your problem.  The fast fix is probably to put `head -1 pattern` in single quotes ('`head -1 pattern`'), but this isn't good programming practice.  A better way is "head -1 pattern" | getline field[2].  And my preference would be to get the value i'm looking to use and pass it into awk using the commandline option -v var=varValue.  Along those same lines instead using the BEGIN block just to set the field seperator, use the -F option to do this. And your END block just prints the values of fields one and two for the last line in your file.&lt;BR /&gt;Assuming you'd like to print the first two fields for everyline (after your modifications). I'd do something like this:&lt;BR /&gt;awk -F: -v var=$(head -1 pattern) &amp;lt; myFile.txt '{&lt;BR /&gt;if ( $1 == "bill" ) $2 = var;&lt;BR /&gt;printf("%s %s\n",$1,$2);&lt;BR /&gt;}' &lt;BR /&gt;</description>
      <pubDate>Sun, 24 Nov 2002 14:44:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850804#M93533</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2002-11-24T14:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: AWK script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850805#M93534</link>
      <description>&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x022718276953d61190040090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x022718276953d61190040090279cd0f9,00.html&lt;/A&gt;</description>
      <pubDate>Sun, 24 Nov 2002 20:10:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850805#M93534</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2002-11-24T20:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: AWK script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850806#M93535</link>
      <description>Try this amendment to your original code:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN { FS = ":" }      &lt;BR /&gt;                             &lt;BR /&gt;{ split($0, field, ":")      &lt;BR /&gt;  if ( field[1] ~ /^bill/ )  &lt;BR /&gt;  {                          &lt;BR /&gt;     cmd = "head -1 pattern" &lt;BR /&gt;     cmd | getline output    &lt;BR /&gt;     close(cmd)              &lt;BR /&gt;     field[2] = output       &lt;BR /&gt;     print field[1], field[2]&lt;BR /&gt;  }                          &lt;BR /&gt;}' myFile.txt&lt;BR /&gt;&lt;BR /&gt;It makes use of one line command substitution using a pipe.  If you have the Oreilly Sed and Awk book, this is well documented with good examples.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Joseph</description>
      <pubDate>Mon, 25 Nov 2002 10:16:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-script/m-p/2850806#M93535</guid>
      <dc:creator>Joseph A Benaiah_1</dc:creator>
      <dc:date>2002-11-25T10:16:50Z</dc:date>
    </item>
  </channel>
</rss>

