I am trying to write a script to convert csv files into SQL format.
What I am missing is:
1. handling of the first row and create it as a insert into format
2. better handling of any other row, and create a line with the data. *The while read line needs a better work.
I thought of using awk.
I will appreciate any help.
This is what I have so far (taken from readfile2.sh script)
PHP Code:
# Make sure we get file name as command line argument
# Else read it from standard input device
if [ "$1" == "" ]; then
echo "No File - Exit"
exit 1
else
FILE="$1"
# make sure file exist and readable
if [ ! -f $FILE ]; then
echo "$FILE : does not exists"
exit 1
elif [ ! -r $FILE ]; then
echo "$FILE: can not read"
exit 2
fi
fi
# field seprator, default is :, you can use blank space or
# other character, if you have more than one blak space in
# input line then use awk utility and not the cut :)
FS=","
while read line
do
# store field 1
F1=$(echo $line|cut -d$FS -f1)
# store field 2
F2=$(echo $line|cut -d$FS -f6)
# store field
F3=$(echo $line|cut -d$FS -f7)
echo "User \"$F1\" home directory is $F2 and login shell is $F3"
done < $FILE