I'm trying to split a csv file with too many rows into chunks of user defined no. of rows, using the following script using awk but its not generating any output, the file is created but its blank. Pls Can anyone point out what's missing...
# !/bin/bash
File=filename.csv
count=`awk 'END {print NR}' $File`
i=2
j=5000
k=$j
while [ $j -le $count ]
do
awk 'NR==1 {print $0}' $File > output"$i".csv
awk 'NR==$i, NR==$j {print $0}' $File > output"$i".csv
i=`expr $j + 1`
j=`expr $i + $k`
if [ $j -gt $count ]
then
j=$count
k=`expr 0 - 1`
elif [ $j -eq $count]
then
break
fi
done