Wrap a single field with single quotes using awk
<p>There are a number of examples using awk to wrap fields with double quotes.  I have unsuccessfully been trying to enclose a field with single quotes for data loading csv files in postgresql.</p>

<p>Below are a few of my attempts:</p>

<pre><code>#!/usr/bin/awk -f
BEGIN { FS=OFS=","}

{
  for (i = 1; i &lt;= NF; ++i)
    if($i == 9)
    {
        $i = "\'' $i \''"
    }

  print $0 &gt;&gt; "output.csv"
}
</code></pre>

<p>or</p>

<p><code>awk 'BEGIN { OFS=FS="," } { $9= ""'" $9 ""'"} 1' container.csv &gt; output.csv</code></p>

<p>also...</p>

<pre><code>awk -v q="'" 'BEGIN { FS="," } { sub($9, ""\'"&amp;"\'"" );print}' container.csv &gt; output.csv
</code></pre>