Take always the last x fields

Hi,

I have a bash script that converts .csv files to sql inserts and so far has worked great. It takes the values and does it's magic.
The thing is that now the .csv files have fields that I don't need, and they are always in the beggining of the line. For example:
One .cvs will have all the lines like:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10

And another one wil have:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13

And so on, but I will always only need the last 5 fields and discard the rest.

Haw can I achieve this?

Thank you!

PS: This is my current full script

#!/bin/bash


################################
# Extensi�n a buscar
EXT="*.csv"

# Ruta completa hacia la carpeta de origen Lotes
IN="/root/Script/In/"

# Ruta completa hacia la carpeta de destino Lotes
OUT="/root/Script/Out/"

# Ruta completa hacia la carpeta de destino SQLs
SQL="/root/Script/SQLs/"

# Ruta completa hacia la carpeta de logs
LOG="/root/Script/Logs/procesador.log"

# Tiempo de espera entre b�squedas en segundos
SEC="3"

################################
Tomar_datos()
{
local tmp=`mktemp temp.uno`
cat $nombre > $2
cat $2 > $tmp
mv $tmp $2
}
################################


################################
Reemplazar_separador()
{
local cnt=`wc -l $nombre | cut -f1 -d" "`
local tmp=`mktemp temp.dos`

cnt=$((cnt - 1))
tail -n $cnt temp.datos > $tmp
mv $tmp temp.datos
}
################################

################################
Armar_inserts()
{
local tmp=`mktemp temp.tres`
cat > $tmp <<-EOF
{print "INSERT INTO $2 (APP_ID, APP_ISS_ID, APPCRD_TSN, CRD_SNR,CRD_INTSNR, DATAFILE_ID,DEV_ID, DEV_STAT, DEV_TSN,DEV_TYPE, EMPL_ID, EMPL_TYPE, ERROR_CODE, ERROR_INTCODE,TRX_FAREVALUE, GROUP_FNAME, GROUP_ID, LINE_ID, PLACE_ID, PROVIDER_ID, PROVIDER_ROLE, PURSE_AMOUNT, PURSE_ID, TRX_ID,TRX_DATETIME, REG_SEQ, CARDNUMBER, ID_LOTE, FLG_MULTPURSE, CARD_BALANCE, FARE_RULE) values(" \$1 ", "\$2 ", "\$3 ", "\$4 ", "\$5 ", "\$6 ", "\$7 ", "\$8 ", "\$9 ", "\$10 ", "\$11 ", "\$12 ", "\$13 ", "\$14 ", "\$15 ", '"\$16 "', "\$17 ", "\$18 ", "\$19 ", "\$20 ", "\$21 ", "\$22 ", "\$23 ", "\$25 ", TO_DATE( '"\$26 ":segundos', 'DD/MM/YYYY HH24:MI:SS'), "\$28 ", "\$29 ", "\$33 ", "\$27 ", "\$24 ", "\$15 "); "}
EOF
cat temp.datos | awk -F, -f $tmp > "$nombre.sql"
rm $tmp
echo "" >> "$nombre.sql"
echo "commit;" >> "$nombre.sql"
}
################################


################################
main()
{
# Copiando registros
local tmp=`mktemp temp.datos`

# Tomando registros
Tomar_datos $nombre $tmp

# Reemplazando separador de registros
Reemplazar_separador $tmp
#sed -i 's/,/./g' temp.datos #Reemplazando separador decimal
sed -i 's/;/,/g' temp.datos

# Armando los inserts
Armar_inserts $tmp $2
rm $tmp
#rm $nombre.sql
}
################################


################################
Tomar_lote ()
{
if [ "$nombre" == "*.csv" ]; then
   unset nombre
   echo "Nada para procesar. Volviendo a buscar en $SEC segundos." >> $LOG
   sleep $SEC
else
   FILE="$nombre"
   # Asegurarse que el archivo exista
   if [ ! -f $FILE ]; then 
	echo "Nada para procesar. Volviendo a buscar en $SEC segundos." >> $LOG
  	sleep 3
	Tomar_lote "$@"
   elif [ ! -r $FILE ]; then
   echo fail 
   fi
   START=$(date +%s)
   echo Procesando Lote $nombre >> $LOG
   main "$@"
   mv $nombre $OUT #Mueve el lote a la carpeta de destino
   mv $nombre.sql $SQL #Mueve el sql a la carpeta de destino
   echo Lote $nombre procesado en $(expr $(date +%s) - $START) segundos  >> $LOG
fi
}
################################

cd $IN
while [ 1 = 1 ]
do
	for nombre in $EXT; 
	do Tomar_lote "$@"
	done
	date echo "Nada para procesar. Volviendo a buscar en $SEC segundos." >> $LOG
	sleep $SEC
done

Something like this?

awk -F", " '{for(i=NF-4;i<NF;i++){printf("%s, ", $i)}print $NF}' file
[house@leonov] cat data.file | awk -F ", " '{print $(($NF-4)),$(($NF-3)),$(($NF-2)),$(($NF-1)),$NF}'
6 7 8 9 10
9 10 11 12 13

This did the trick.

Thank you very much!