<?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, piping, replacing a string in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772228#M942243</link>
    <description>Part I.&lt;BR /&gt;&lt;BR /&gt;I dont know of a way to do this with awk, but someone on here may know how.  You could do what you are talking about with 'sed' however.  It would need to be something like:&lt;BR /&gt;&lt;BR /&gt;sed -e 's/${celebrity}:${job}:man/${celebrity}:${job}:woman/'&lt;BR /&gt;&lt;BR /&gt;Part II.&lt;BR /&gt;&lt;BR /&gt;I would do something like:&lt;BR /&gt;&lt;BR /&gt;cat celebrity.csh | grep -v $celebrity &amp;gt; celebrity2.csh&lt;BR /&gt;mv celebrity2.csh celebrity.csh&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;&lt;BR /&gt;Brian&lt;BR /&gt;</description>
    <pubDate>Thu, 25 Jul 2002 05:52:29 GMT</pubDate>
    <dc:creator>Brian Crabtree</dc:creator>
    <dc:date>2002-07-25T05:52:29Z</dc:date>
    <item>
      <title>awk, piping, replacing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772227#M942242</link>
      <description>&lt;BR /&gt;I have a 2 part question:&lt;BR /&gt;&lt;BR /&gt;PART I:&lt;BR /&gt;&lt;BR /&gt;i have a file database of variables in the form&lt;BR /&gt;&lt;BR /&gt;var1:var2:var3:::&lt;BR /&gt;&lt;BR /&gt;ex.&lt;BR /&gt;&lt;BR /&gt;%celebrities.csh&lt;BR /&gt;michael jordan:basketball player:man::&lt;BR /&gt;britney spears:singer:woman::&lt;BR /&gt;madonna:singer:woman:::&lt;BR /&gt;&lt;BR /&gt;---------------------------------------&lt;BR /&gt;looking at this code snippet:&lt;BR /&gt;&lt;BR /&gt; echo -n "\nEnter a celebrity: " &lt;BR /&gt;   set celebrity = $&amp;lt; &lt;BR /&gt;   echo -n "Enter Job: " &lt;BR /&gt;   set job = $&amp;lt; &lt;BR /&gt;&lt;BR /&gt;if (`fgrep -c "${celebrity}" celebrity.csh`) then &lt;BR /&gt;   &lt;BR /&gt;(`fgrep -w "${celebrity}" celebrity.csh`) | fgrep ":man:" | awk -F: -f celebrity.csh '{printf "$3=%s", woman}' &lt;BR /&gt;&lt;BR /&gt;else &lt;BR /&gt;    echo -n "***Error*** No Celebrity by tht Name" &lt;BR /&gt;    goto MainMenu &lt;BR /&gt;endif &lt;BR /&gt;-------------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;###i am trying to first check if the celebrity entered by the user is in my database (this works)&lt;BR /&gt; then  &lt;BR /&gt;  pipe the result of that line to another search that checks to see if that celebrity is a man (this also works)&lt;BR /&gt;  then if true (is a man) pipe that into an awk command that would change the 3rd varible value in that database file (in this case "man") to "woman"&lt;BR /&gt;(this part is not working for me)&lt;BR /&gt;&lt;BR /&gt;...so ex:&lt;BR /&gt;if user enter michael jordan, it performs a search to see if he is in the database file called celebrities.csh, &lt;BR /&gt; then checks to see if he is a man, &lt;BR /&gt;  then should change the man variable to woman so if i looked at the celebrities.csh file it should look like this:&lt;BR /&gt;&lt;BR /&gt;michael jordan:athlete:woman::  ##man status changed&lt;BR /&gt;britney spears:singer:woman::&lt;BR /&gt;madonna:singer:woman:::&lt;BR /&gt;&lt;BR /&gt;i am not familiar with the awk utility and would like assistance in doing this please...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Also PART II:&lt;BR /&gt;&lt;BR /&gt;using same database file, after having the user enter a celebrity, and do the search to see if they are in the database, how would i code i guess another awk command to remove that line that contains the entered celebrity from the database file??&lt;BR /&gt;&lt;BR /&gt;---------------------------------------&lt;BR /&gt;looking at this code snippet:&lt;BR /&gt;&lt;BR /&gt; echo -n "\nEnter a celebrity: " &lt;BR /&gt;   set celebrity = $&amp;lt; &lt;BR /&gt;   echo -n "Enter Job: " &lt;BR /&gt;   set job = $&amp;lt; &lt;BR /&gt;&lt;BR /&gt;if (`fgrep -c "${celebrity}" celebrity.csh`) then &lt;BR /&gt;   &lt;BR /&gt;##remove that matching line&lt;BR /&gt;&lt;BR /&gt;else &lt;BR /&gt;    echo -n "***Error*** No Celebrity by tht Name" &lt;BR /&gt;    goto MainMenu &lt;BR /&gt;endif &lt;BR /&gt;-------------------------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;any help would be appreciated!&lt;BR /&gt;thanks,&lt;BR /&gt;jada &lt;BR /&gt;</description>
      <pubDate>Thu, 25 Jul 2002 03:56:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772227#M942242</guid>
      <dc:creator>tskanes</dc:creator>
      <dc:date>2002-07-25T03:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: awk, piping, replacing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772228#M942243</link>
      <description>Part I.&lt;BR /&gt;&lt;BR /&gt;I dont know of a way to do this with awk, but someone on here may know how.  You could do what you are talking about with 'sed' however.  It would need to be something like:&lt;BR /&gt;&lt;BR /&gt;sed -e 's/${celebrity}:${job}:man/${celebrity}:${job}:woman/'&lt;BR /&gt;&lt;BR /&gt;Part II.&lt;BR /&gt;&lt;BR /&gt;I would do something like:&lt;BR /&gt;&lt;BR /&gt;cat celebrity.csh | grep -v $celebrity &amp;gt; celebrity2.csh&lt;BR /&gt;mv celebrity2.csh celebrity.csh&lt;BR /&gt;&lt;BR /&gt;Hope this helps,&lt;BR /&gt;&lt;BR /&gt;Brian&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Jul 2002 05:52:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772228#M942243</guid>
      <dc:creator>Brian Crabtree</dc:creator>
      <dc:date>2002-07-25T05:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: awk, piping, replacing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772229#M942244</link>
      <description>Hi, what about this:&lt;BR /&gt;&lt;BR /&gt;-v option to import variable&lt;BR /&gt;FS is set Field Seperator&lt;BR /&gt;&lt;BR /&gt;# change gender to woman&lt;BR /&gt;INPUTFILE=celebrities.csh&lt;BR /&gt;NAME="michael jordan" # set by reading input yourself&lt;BR /&gt;&lt;BR /&gt;awk -v name=$NAME 'BEGIN{FS=":"}{&lt;BR /&gt;if ($1=name) { print "$1:$2:woman::" }&lt;BR /&gt;else { print $0 }&lt;BR /&gt;}' $INPUTFILE&lt;BR /&gt;&lt;BR /&gt;=========&lt;BR /&gt;&lt;BR /&gt;# switch gender if found&lt;BR /&gt;awk -v name=$Name 'BEGIN{FS=":"}{&lt;BR /&gt;if ($1=name) {&lt;BR /&gt;   if ($3="man") { print "$1:$2:woman::" }&lt;BR /&gt;   else { print "$1:$2:man::" }&lt;BR /&gt;else { print $0 }&lt;BR /&gt;}' $INPUTFILE &lt;BR /&gt;&lt;BR /&gt;=========&lt;BR /&gt;&lt;BR /&gt;# delete found celeb&lt;BR /&gt;awk -v name=$Name 'BEGIN{FS=":"}{&lt;BR /&gt;if ($1!=name) { print $0 }&lt;BR /&gt;}' $INPUTFILE&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ceesjan</description>
      <pubDate>Thu, 25 Jul 2002 06:23:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772229#M942244</guid>
      <dc:creator>Ceesjan van Hattum</dc:creator>
      <dc:date>2002-07-25T06:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: awk, piping, replacing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772230#M942245</link>
      <description>thanks guys&lt;BR /&gt;&lt;BR /&gt;because of yall i was able to figure alot of things out and get my program on it's way to being finished....&lt;BR /&gt;&lt;BR /&gt;you guys are great&lt;BR /&gt;&lt;BR /&gt;;o]&lt;BR /&gt;jada</description>
      <pubDate>Thu, 25 Jul 2002 12:21:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-piping-replacing-a-string/m-p/2772230#M942245</guid>
      <dc:creator>tskanes</dc:creator>
      <dc:date>2002-07-25T12:21:50Z</dc:date>
    </item>
  </channel>
</rss>

