I want to replace some values with bash in a csv file like this:
age,sex,bmi,smoker,region,charges
19,female,27.9,yes,southwest,16884.924
23,male,29.83,no,northeast,1725.5523
Basically, I need to replace the binary fields with 0 or 1 values. My code is the following:
filename="$1"
IFS=,
while read -ra values; do
 
  case "${values[1]}" in
  male)    values[1]=0 ;;
  female)  values[1]=1 ;;
  esac
  
  case "${values[4]}" in
  yes) values[4]=1 ;;
  no)  values[4]=0 ;;
  esac
    
done
} < $filename
I am executing the script with the calling:
./b.sh insurance.csv
I don't know what I have wrong but the csv does not update with the new values.
 
    