Script to split files based on number of lines

I am getting a few gzip files into a folder by doing ftp to another server. Once I get them I move them to another location .But before that I need to make sure each gzip is not more than 5000 lines and split it up . The files I get are anywhere from 500 lines to 10000 lines in them and is in gzip format.

#!/bin/sh
echo "get gzip files"
sftp user1@server1<<EOF
get *.gzip
quit
EOF
for each in *.gzip;
        do
        mv $each /home/newlocation
        done << EOF

As far as i know you can check how many lines in your .gz file with this:

>gunzip -c backup.sql.gz | wc -l
  262144

and then you can use this value in your script, in a comparision loop as a variable, counter etc.

gunzip -c $each |split -l 5000

Thanks. There is a small problem . It doesnt retain the original name.

For example if my file is Server.log.1023.gzip when I do
gunzip -c Server.log.1023.gzip|split -l 5000 I get
xaa
xab
xac

I would like to get
Server.log.1023_a.gzip
Server.log.1023_b.gzip

or something in that nature.

Thanks in advance

You can set prefix with

split [OPTION] [INPUT [PREFIX]]