title: How to modify a column of a csv in bash
body: <p>Edit, this is how I modified the full file following the suggestions.
  It's still not working as expected: the 4th column is printed as empty value in the stdout and the myCSV.csv is not altered by the applied function:</p>
  
  <pre><code>#!/bin/bash
  
  function dec2ip() {
     local ip dec=$@
     for e in {3..0}
        do
           ((octet = dec / (256 ** e) ))
           ((dec -= octet * 256 ** e))
           ip+=$delim$octet
           local delim=.
        done
  # printf '%s\n' "$ip"
  }
  dec2ip "$@"
  
  
  decimal_subnets=( $(cut -d ',' -f4 /test/myCSV.csv ) )
  
  echo ${#decimal_subnets[@]}
  
  (
  # print the header untouched
  read line; echo "$line"
  IFS=,
  while read -ra fields; do
      fields[3]=$(dec2ip "${fields[3]}")
      echo "${fields[*]}" &gt;&gt; /test/myCSV_dotted.csv
  done
  ) &lt; /test/myCSV.csv
  </code></pre>
  
  <p>That's the output I see on the command line and the same content that appears in myCSV_dotted.csv (basically, the 4th column is "missing"):</p>
  
  <pre><code>VLAN ID,NAME,DESCRIPTION,SUBNET
  11,txt1,txt2,
  12,txt3,txt4,
  13,txt5,txt6,
  </code></pre>
  
  <p>Sample input is:</p>
  
  <pre><code>VLAN ID,NAME,DESCRIPTION,SUBNET 
  11,txt1,txt2,123456
  12,txt3,txt4,789012
  13,txt5,txt6,345678
  </code></pre>
  
  <p>It seems that the function <code>dec2ip()</code> is not providing the right result: what am I missing?</p>