<?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: Double-Quotes In awk in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152914#M683883</link>
    <description>Hi Mike:&lt;BR /&gt;&lt;BR /&gt;Try:&lt;BR /&gt;&lt;BR /&gt;# awk '{gsub("\,\,", ",\"\",");print}' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
    <pubDate>Tue, 27 Jan 2009 19:00:30 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-01-27T19:00:30Z</dc:date>
    <item>
      <title>Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152912#M683881</link>
      <description>I have been handed a comma-separated file whose records look like&lt;BR /&gt;&lt;BR /&gt;"124","124",,60.00,60.00,60.00,0.00,0.45,60.45,0.059000,"APP","00","EXC"&lt;BR /&gt;&lt;BR /&gt;I need to awk or sed this stuff so its output looks like&lt;BR /&gt;&lt;BR /&gt;"124","124","","60.00","60.00","60.00","0.00","0.45","60.45","0.059000","APP","00","EXC"&lt;BR /&gt;&lt;BR /&gt;In other words, if a "field" is already surrounded by double-quotes, pass it thru.  If the field is *NOT* surrounded by double-quotes, I need to output them doing so.  And, if a field between commas is empty, I need to parse out a placeholder set of quotes.&lt;BR /&gt;&lt;BR /&gt;I know my awk command would be something of the form&lt;BR /&gt;&lt;BR /&gt;awk -F, -f [progfile]&lt;BR /&gt;&lt;BR /&gt;and that [progfile] will of the form&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;for(i=1;i&amp;lt;=NF;i++)&lt;BR /&gt;   {&lt;BR /&gt;   if(there's a quote already)&lt;BR /&gt;     {printf("%s,",$i)}&lt;BR /&gt;   else&lt;BR /&gt;     {printf("\"%s\",",$i)}&lt;BR /&gt;   }&lt;BR /&gt;printf("\n")&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;What's got me stumped is how to detect that field N already begins and ends with a double-quote.  Pretty much anything I've tried&lt;BR /&gt;&lt;BR /&gt;if(match($i,/\"/)!=0)&lt;BR /&gt;&lt;BR /&gt;if($i~/^'"'/)&lt;BR /&gt;&lt;BR /&gt;if($i~/^'"'/)&lt;BR /&gt;&lt;BR /&gt;has caused awk to barf on another statement, presumably because I have unbalanced quotes where I'm not escaping something correctly (perhaps in that last mondo printf statement?).&lt;BR /&gt;&lt;BR /&gt;Unfortunately, perl is not an option for me, and I'm not a high-enough muckety-muck to insist that it be installed.  Therefore, I'm thinking I'm going to have to stick with awk, unless someone has some sed or other text-processing capital-m Magic they can share.&lt;BR /&gt;&lt;BR /&gt;Help?</description>
      <pubDate>Tue, 27 Jan 2009 18:46:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152912#M683881</guid>
      <dc:creator>Michael Mike Reaser</dc:creator>
      <dc:date>2009-01-27T18:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152913#M683882</link>
      <description>&amp;gt;is how to detect that field N already begins and ends with a double-quote.&lt;BR /&gt;&lt;BR /&gt;You can use substr to extract chars from strings:&lt;BR /&gt;if (substr($i,1,1) == "\"")</description>
      <pubDate>Tue, 27 Jan 2009 18:52:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152913#M683882</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-01-27T18:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152914#M683883</link>
      <description>Hi Mike:&lt;BR /&gt;&lt;BR /&gt;Try:&lt;BR /&gt;&lt;BR /&gt;# awk '{gsub("\,\,", ",\"\",");print}' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jan 2009 19:00:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152914#M683883</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-01-27T19:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152915#M683884</link>
      <description>&amp;gt;You can use substr to extract chars from strings&lt;BR /&gt;&lt;BR /&gt;D'oh.  Thank you, Dennis.  As you may or may not recall, I have quite a knack for figuring out the Most Complicated Way Possible to accomplish tasks.  Cutting thru the muck and just testing substr($i,1,1) and substr($i,1,length($i)) for quotes Did The Trick.</description>
      <pubDate>Tue, 27 Jan 2009 19:03:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152915#M683884</guid>
      <dc:creator>Michael Mike Reaser</dc:creator>
      <dc:date>2009-01-27T19:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152916#M683885</link>
      <description>Are there potentially embedded commas or double-quotes in the quoted strings?&lt;BR /&gt;&lt;BR /&gt;If not, just strip all double-quotes, replace commas with "," and start and end with a doublequote.&lt;BR /&gt;&lt;BR /&gt;Are you sure perl is not simple on the box?&lt;BR /&gt;Anyway...&lt;BR /&gt;&lt;BR /&gt;$ cat tmp.txt&lt;BR /&gt;"124","124",,60.00,60.00,60.00,0.00,0.45,60.45,0.059000,"APP","00","EXC"&lt;BR /&gt;&lt;BR /&gt;$ awk '{gsub(/"/,""); gsub(/,/,"\",\""); print "\"" $0 "\""}' tmp.txt&lt;BR /&gt;"124","124","","60.00","60.00","60.00","0.00","0.45","60.45","0.059000","APP","00","EXC"&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;$ perl -pe 's/"//g;s/,/","/g;$_; s/^/"/; s/.$/"/' tmp.txt&lt;BR /&gt;"124","124","","60.00","60.00","60.00","0.00","0.45","60.45","0.059000","APP","00","EXC"&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Jan 2009 19:05:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152916#M683885</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2009-01-27T19:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152917#M683886</link>
      <description>JRF:&amp;gt;  awk '{gsub("\,\,", ",\"\",");print}' file&lt;BR /&gt;&lt;BR /&gt;Thankee!  That *almost* got me there, but missed putting quotes around the non-quoted numeric fields.  :-/  However, Hein's suggestion worked like a charm.  :-)&lt;BR /&gt;&lt;BR /&gt;(And I know the "no Perl" stuff had to have driven you nutty.  It's not got me all that happy, myself, but I've got to work within the handcuffs I've been handed...)</description>
      <pubDate>Tue, 27 Jan 2009 19:23:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152917#M683886</guid>
      <dc:creator>Michael Mike Reaser</dc:creator>
      <dc:date>2009-01-27T19:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152918#M683887</link>
      <description>Hein:&amp;gt; Are there potentially embedded commas or double-quotes in the quoted strings? &lt;BR /&gt;&lt;BR /&gt;Double-quotes, no.  Commas, it doesn't *appear* that commas are An Issue, but all I've been handed thus far is "toy data".  &lt;BR /&gt;&lt;BR /&gt;Hein:&amp;gt; Are you sure perl is not simple on the box? &lt;BR /&gt;&lt;BR /&gt;Unfortunately, yes, I'm sure.  :-( :-( :-(</description>
      <pubDate>Tue, 27 Jan 2009 19:26:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152918#M683887</guid>
      <dc:creator>Michael Mike Reaser</dc:creator>
      <dc:date>2009-01-27T19:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Double-Quotes In awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152919#M683888</link>
      <description>A combination of Dennis's, JRF's and Hein's suggestions got me over the hump.  As always, thank you!!!</description>
      <pubDate>Tue, 27 Jan 2009 19:31:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/double-quotes-in-awk/m-p/5152919#M683888</guid>
      <dc:creator>Michael Mike Reaser</dc:creator>
      <dc:date>2009-01-27T19:31:38Z</dc:date>
    </item>
  </channel>
</rss>

