#!/bin/bash USER="root" DATABASE="students" TABLE="students" if [ $# -ne 1 ]; then echo $0 DATAFILE echo exit 2 fi data=$1 while read line; do oldIFS=$IFS IFS=, values=($line) values[1]=""`echo ${values[1]} | tr ' ' '#' `"" values[3]=""`echo ${values[3]}`"" query=`echo ${values[@]} | tr ' #' ', '` IFS=$oldIFS statement=`echo "INSERT INTO $TABLE VALUES($query);"` # echo $statement mysql -u $USER $DATABASE -p << EOF INSERT INTO $TABLE VALUES($query); EOF done < $data if [[ $? -eq 0 ]]; then echo "Wrote data into DB" fi