copying from line N1 to line N2 of a file in a series of files

Dear community,

I'm quite a newbie with scripting, I have this problem:

I have a file with many lines and I want to copy the lines from 1 to N to file.1, from N+1 to 2N to file.2, and so on up to the end of the file

I have tried with something like this (N=43 in this example):

awk '{for (i=1;i<=1000;i++) if ((NR>=$i43 -42)&&(NR<=$i43)) print $0}' big_file >> file.$

but it doesn't output anything, neither does the following:

for ((i=1;i<=1000;i++))
do
awk '{ if ((NR>=$i43 -42)&&(NR<=$i43)) print $0}' big_file >> file.$
done

I've tried other ways, they all failed... do you have any suggestion?

Try this...

i=1
N=100
inputfile=inputfile
total_lines=`wc -l $inputfile|awk '{print $1}`
flag=0
while [[ $flag -eq 0 ]]
do
   (( no_of_lines = $i * $N ))
   if [[ $no_of_lines -gt $total_lines ]]; then
      no_of_lines=$total_lines
      flag=1
   fi
   head -n $no_of_lines $inputfile | tail -n $N > file."$i"
   (( i = $i + 1))
done

that worked, thanks a lot! :stuck_out_tongue:
bests
p